我已经查看了其他相关问题,但没有一个对这个案子有帮助。
我收到问题标题中列出的警告,我的代码main
如下:
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;
}
用户将输入一个数字(例如 4),该数字将被扫描到n
. 该空间被分配用于电话垫的行。然后用户将输入n
用于配置电话板的行数。一个例子是:
123
456
789
.0。
所以我很困惑为什么我的最后一条printf
语句会出现这个错误。
注意:我也试过scanf("%s", rows[i]);
:仍然得到错误。
注意2:我还是尝试运行该程序。出现分段错误。
注 3:我的 .c 程序的顶部有#include <stdio.h>
和。
注 4:我已经 gcc'ed 程序是这样的:.#include <stdlib.h>
gcc -ansi -pedantic -Wall tele.c
感谢您的帮助。