I am trying to write a function which passes on a text and which returns only one line (main objective to check if a character string is in a line if yes to print it if not not to print it) my function get line thus receives character after character thanks to getchar and if the character entered is \ n then get char returns the line. here is what i tried to do:
char get_line(){
int i=0;
char c;
char *s=malloc(MAX_LINE*sizeof (char));
char s[MAX_LINE];
while ((c=getchar())!=EOF){
if (c!='\n'){
s[i]=c;
i++;
}
else{
s[i]='\0'
}
return s;
}
s[i]='\0';
return s;
}
I don't want a code that works better but an explanation why my code does not work