sk wrote:
I'm trying to write a little function that acts very similar to
scanf, but I suck at pointers and returning chars.
My code:
char *getline(){
char *string;
char c;
int i=0;
while((c=getchar())!='\n'){
string[i++]=c;
}
return string;
}
It runs after compilation, but when I use the function, I get a
segmentation fault. Can someone help?
Of course it does, it is putting chars where the sun don't shine.
And it can't return information about EOF, file system errors,
etc. To see a way to implement a suitable function, see:
<http://cbfalconer.home.att.net/download/ggets.zip>
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>