a loop won't break in C -


i have been delving c , rather using scanf() wanna try build own function entire line. wrote function returns line compared in main function, except won't break out of loop print result.

i don't know if it's actual function or how implemented in main().

here's code:

main() {     int len;     int max = 0; //largest line far..     char linetemp[maxline];      char linemax[maxline];     while((len = getline(linetemp,maxline))> 0){         if(len>max){             max = len;             cpy(linemax,linetemp);         }     }        if(max>0) {  //if line         printf("longest line:\n %s \n", linemax);     } else {         printf("no lines found!");     } }  int getline(char l[], int lim) {     int c, i;     for(i=0; i< lim - 1 && (c=getchar())!= '\n' && c != eof ;++i)         l[i]= c;     if(c =='\n') {         l[i]= c;         ++i;     }     l[i]= '\0';     return i; } 

the while loop in main ends if length returned zero, never can unless character read eof. if presses enter, add newline , increment size, 1 returned.

perhaps want remove special case handling of if(c=='\n') , let return empty string if presses enter without other text.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -