以下程序在 gcc 中运行,但在给出 T = 6 的值时,该程序将继续运行,并且不会因要求输入字符串而结束。如果您发现这个程序有什么问题,有什么帮助吗?
int main()
{ int T,i,j;
char *strings[T];
printf("Enter the Number of Strings to Reverse : \n");
scanf("%d ",&T);
for(i=0;i<T;i++)
{ strings[i] = (char *)malloc(100*sizeof(char));
scanf("%s\n",strings[i]);
}
for(i=0;i<T;i++)
{printf(" The String %d is : %s\n",i+1,strings[i]);
}
return 0;
}
最佳答案
T 未初始化(请记住,在 C++ 中,局部作用域变量不会自动初始化):
int T= 6;
关于c - 在C语言中使用指针输入字符串有困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22206413/