Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
我想将字符串(包括空格)输入保存到二维数组。
我的代码是这样的:

char a[10000][6];
scanf("%d", &n);
for (int i = 0;i < n;i++)
{
    scanf("%[^\n]s", a[i]);
}

for (int i = 0;i < n;i++)
{
    printf("%s\n", a[i]);
}


我得到的是错误的输出。请给我任何建议!

最佳答案

采用

char a[10000][6];
scanf("%d",&n);
int i;
for (i = 0;i < n;i++)
{
scanf("%s",&a[i]);
}

关于c - 如何在c中扫描二维char数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43961884/

10-11 21:06