c - 多维数组: Ignoring spaces in the input

标签 c arrays multidimensional-array

我是 C 编程新手,我有一项学校作业,其中用户输入一个 7x7 的谜题(使用多维数组)。我的问题是我不知道如何从输入中删除空格,因为每个字符后面都应该有一个空格。例如:

1 2 1 1 1 1 1
2 2 1 1 1 2 1
1 2 1 1 1 1 1
2 2 1 1 1 2 1
1 2 1 1 1 1 1
2 2 1 1 1 2 1
1 2 1 1 1 1 1

我需要忽略空格,并且每行仍然有 7 个字符。 谢谢! :) 这是我的代码,但它没有运行。

int main(){
char puzzle[7][7];
char input[7][7];
int i;
int j;  
int a;
int b;
for(i=0; i<7; i++){
for(j=0; j<7; j++){
    fgets(input[i][j],sizeof(input[i][j]), stdin);
        for(i=0, j=0; i,j<strlen(input[i][j]); i++,j++){
            if(input[i][j]==' ')
                continue;
                puzzle[a][b]=input[i][j];
                a++;
                b++;
            }
        }
    }
getch();
}

最佳答案

int a[7][7];
for (int i = 0; i < 7 ; i++)
    for (int j = 0; j < 7 ; j++)
        scanf("%i",&a[i][j]);

scanf("%i",&a[i][j]); 将忽略空格和换行符。

关于c - 多维数组: Ignoring spaces in the input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22269079/

相关文章:

c++ - 实现插件支持的最佳方式

c++ - C++ 中的 Websocket 客户端

java - 检查三角形阵列中的邻接

java - 二维数组列表 Java (Gui)

c - 从以前保存的文件加载时缓冲区溢出

c++ - 对演示场景大小限制有何影响?

arrays - ScalaTestFailureLocation 预期的 StructField(value1,ArrayType(StringType,true),false) 实际的 StructField(val2,ArrayType(StringType,true),true)

arrays - Scala 分配顺序索引数组

c++ - C/C++ 如何在没有嵌套循环的情况下复制多维字符数组?

javascript - 将数组推送到多维数组