#include #include #include "sortlin.h" #define MAXLEN 1000 /* max. duzina ulaznog reda */ int readlines( char *lineptr[], int maxlines) /* ucitavanje ulaznog reda */ { int len, nlines; char *p, line[MAXLEN]; // line je pomocni bafer nlines = 0; while((len = getline(line, MAXLEN)) > 0 ) if( nlines >= maxlines || (p = (char *) malloc(len)) == NULL) return -1; else { line[len - 1] = '\0'; /* izbaci novi red */ strcpy(p, line); lineptr[nlines++] = p; } return nlines; } /* unos linije i odredjivanje duzine (sa '\0') */ int getline( char s[], int lim ) { int c, i; i = 0; while( --lim > 0 && (c = getchar()) != EOF && ( c != '\n' ) ) s[i++] = c; if( c == '\n' ) s[i++] = c; s[i] = '\0'; return i; }