int main(int argc, char* argv[]){ extern char reverse; extern compare pf; short c; int index; int lineno; int linelen; char number; char line[LINE_LIMIT]; char* lines[LINE_NUMBER]; number = 0; while(--argc > 0 && (*++argv)[0] == '-'){ while( (c=*++argv[0]) ){ switch(c){ case 'r': { reverse = 1; break;} case 'n': { number = 1; break;} default: { printf("invalid flag\n"); break;} } } } if(argc != 0){ printf("Usage: sort -r -n\n"); } if(number == 1){ pf = cmpnumber; } lineno = 0; while( (linelen = getnewline(line, LINE_LIMIT)) ){ lines[lineno] = memalloc(linelen + 1); strcpy(*(lines+lineno++), line); } quicksort(lines, 0, lineno-1); for(index=0; index<lineno; index++){ printf(number == 1? "%s\n" : "%s", lines[index]); } return 0; }
int main(int argc, char* argv[]){ short c; int lineno; int except, number, found; char line[LINE_LIMIT]; lineno = 0; except = 0; number = 0; found = 0; while(--argc > 0 && (*++argv)[0] == '-'){ while( (c = *++argv[0]) ){ switch(c){ case 'x': { except = 1; break;} case 'n': { number = 1; break;} default: { printf("find: illegal option %c \n", c); argc = 0; found = -1; break;} } } } if(argc != 1){ printf("Usage: find -x -n pattern\n"); }else{ while(getnewline(line, LINE_LIMIT) > 0){ lineno++; if((strstr(line, *argv) != NULL) != except){ if(number){ printf("%d: ", lineno); } printf("%s", line); found++; } } } return found; }
int main() { int i=0,j=0,n; char line[MAXLEN]; char *lines[MAXLINES]; while((n=getnewline(line, MAXLEN)) > 0) { lines[i]= (char *)malloc(n*sizeof(int));; strcpy(lines[i], line); i++; } while(j<=i) { printf("%s", lines[j++]); //free(lines[j]); } return 0; }
int main(void){ int cursor; int indexofline; char lines[LINE_NUMBER][LINE_LIMIT]; indexofline = 0; while(getnewline(lines[indexofline], LINE_LIMIT)){ indexofline++;} cursor=0; for(cursor=0; cursor<indexofline; cursor++){ printf("index %d of lines is %s.", cursor, lines[cursor]); } return 0; }
int main() { int len; extern int max; extern char longest[]; max = 0; while((len = getnewline()) > 0) { if (len > max) { max = len; copy(); } if (max > 0) { printf("%s", longest); } return 0; } }
main() { int len, max; char line[MAXLINE]; /* linea actual */ char longest[MAXLINE]; /* linea mas larga */ max = 0; while ((len = getnewline(line, MAXLINE)) > 0) if (len > max) { max = len; copy(longest, line); } if (max > 0) /* hay una linea */ printf("%s", longest); return 0; }
int main(int argc, char* argv[]){ short c; int lineno; int linelen; int toprint; char linebuffer[LINE_LIMIT]; char* lines[LINE_NUMBER]; toprint = -1; while(--argc > 0 && (*++argv)[0] == '-'){ while((c=*++argv[0])){ switch(c){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { if(toprint == -1){ toprint = 0;} toprint = toprint * 10 + c - '0'; break;} default: { printf("unknow flags to the tail.\n"); break;} } } } if( argc != 0 || toprint == -1){ printf("Usage: tail -n\n"); return -1; } lineno = 0; while((linelen=getnewline(linebuffer, LINE_LIMIT)) > 0){ lines[lineno] = memalloc(linelen+1); strcpy(lines[lineno++], linebuffer); } while(toprint-- > 0){ if(--lineno >= 0){ printf("%d: %s", lineno+1, lines[lineno]); } } return 0; }
int main(){ char *S = getnewline(); printf("%s\n", S); free(S); return 0; }