c - Scanf Seg Fault -
i'm working on assignment c course, , i'm trying take in user's input , store in variable use later in code. here's main function looks like,
int main() { // variables here char* inputline[10]; { printf("insert number...."); scanf("%s\n", inputline); // more stuff here } return 0; } this code gives me bunch of warnings, warning: format specifies type 'char *' argument has type 'char **' [-wformat], , if change variable declaration to,
char* inputline = null; when execute code seg fault, can explain me doing wrong, , differences of happens in memory when i'm initializing variable?
char* inputline[10];
--> array of ten pointers char
printf's format %s expects argument of type char *, you're providing type char **
just use
char inputline[10];
to avoid possible buffer overflow should use
scanf("%9s", inputline); //notice size %s
9 because c string null terminated ('\0') 1 byte goes @ end
Comments
Post a Comment