I have already looked at other related questions, and none of them helped this case.
I am getting the warning listed in the title of my question, and my code for main
is as follows:
int main( int argc, char *argv[] ) {
char *rows;
int i, n;
printf("\nEnter the amount of rows in the telephone pad: ");
scanf("%d", &n);
rows = (char *) malloc( sizeof( char ) * n );
printf("\nNow enter the configuration for the pad:\n");
for( i = 0; i < n; i++ ) {
scanf("%s", &rows[i]);
printf("\n\t%s\n", rows[i]);
}
return 0;
}
The user is to enter a number (say, 4), which will be scanned into n
. The space is malloc'ed for the rows of the telephone pad. The user then will enter the n
amount of rows for the configuration of the telephone pad. An example would be:
123
456
789
.0.
So I am confused as to why my last printf
statement is getting this error.
Note: I also tried scanf("%s", rows[i]);
: still got the error.
Note 2: I tried running the program anyways. Got a segmentation fault.
Note 3: I have #include <stdio.h>
and #include <stdlib.h>
at the top of my .c program.
Note 4: I have gcc'ed the program as such: gcc -ansi -pedantic -Wall tele.c
.
Thank you for the help.
rows[i]
isn't a char*
-- it's not a "string".
(And you can't fit 3 characters (plus null terminator) in one character.)