S
sk
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?
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?