Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用循环向“0”数组添加字符时出现问题;“字符串”;在c中?_C_Arrays_String_Char - Fatal编程技术网

使用循环向“0”数组添加字符时出现问题;“字符串”;在c中?

使用循环向“0”数组添加字符时出现问题;“字符串”;在c中?,c,arrays,string,char,C,Arrays,String,Char,所以我尝试了数据类型char和数据类型int.Nomatter,printf只显示输入单词的第一个字母。例如,如果有人输入dog,它只会说“d”。 我猜可能单词[i]的语法只取第一个字母,但我不知道如何修复它。 有人知道如何解决这个问题吗 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define p

所以我尝试了数据类型char和数据类型int.Nomatter,printf只显示输入单词的第一个字母。例如,如果有人输入dog,它只会说“d”。 我猜可能单词[i]的语法只取第一个字母,但我不知道如何修复它。 有人知道如何解决这个问题吗

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #define pause system("pause")
    #define cls system("cls")


void getUserWords(int *counter, int words[]){
            int i;

            printf("How many words would you like to enter into the cross word puzzle\n");
            scanf("%i",&*counter);
            for(i=0; i < *counter; i++){
                printf("Please enter word #%i\n",i+1);
                scanf("%s",&words[i]);
                printf("The word %c will be added to the crossword puzzle\n",words[i]);
                pause;
                cls;
            }//end for

            printf("Your all your words have been successfully added to the crossword puzzle");
            cls;
        }//end getUserWords
#包括
#包括
#包括
#包括
#定义暂停系统(“暂停”)
#定义cls系统(“cls”)
void getUserWords(int*计数器,int words[]){
int i;
printf(“您希望在纵横字谜中输入多少单词\n”);
扫描频率(“%i”和*计数器);
用于(i=0;i<*计数器;i++){
printf(“请输入单词#%i\n”,i+1);
scanf(“%s”和单词[i]);
printf(“单词%c将被添加到纵横字谜中,\n”,单词[i]);
暂停;
cls;
}//结束
printf(“您的所有单词已成功添加到纵横字谜中”);
cls;
}//结束getUserWords

如果您阅读了与printf()和朋友相关的C库文档, 您可能还记得“%c”是单个字符的格式字符串。如果 如果要将字符串打印到终止NULL,应使用“%s”

你有:

 printf("The word %c will be added to the crossword puzzle\n",words[i]);
但是你应该

 printf("The word %s will be added to the crossword puzzle\n",words[i]);

另外,确保函数的第二个参数有足够的空间来存储
计数器
字。

如果您阅读了与printf()和friends相关的C库文档, 您可能还记得“%c”是单个字符的格式字符串。如果 如果要将字符串打印到终止NULL,应使用“%s”

你有:

 printf("The word %c will be added to the crossword puzzle\n",words[i]);
但是你应该

 printf("The word %s will be added to the crossword puzzle\n",words[i]);

另外,确保函数的第二个参数有足够的空间来存储
计数器
字。

如果您阅读了与printf()和friends相关的C库文档, 您可能还记得“%c”是单个字符的格式字符串。如果 如果要将字符串打印到终止NULL,应使用“%s”

你有:

 printf("The word %c will be added to the crossword puzzle\n",words[i]);
但是你应该

 printf("The word %s will be added to the crossword puzzle\n",words[i]);

另外,确保函数的第二个参数有足够的空间来存储
计数器
字。

如果您阅读了与printf()和friends相关的C库文档, 您可能还记得“%c”是单个字符的格式字符串。如果 如果要将字符串打印到终止NULL,应使用“%s”

你有:

 printf("The word %c will be added to the crossword puzzle\n",words[i]);
但是你应该

 printf("The word %s will be added to the crossword puzzle\n",words[i]);

另外,请确保函数的第二个参数有足够的空间来存储
计数器
字。

int words[]
字是一个整数数组,只能保存指定大小的整数。
现在,当您使用,
scanf(“%s”)和&words[i])您正在尝试将字符串读入正确的每个整数位置。这就是即使输入字符串也只能存储第一个字符的原因。

int words[]
words是一个整数数组,只能保存指定大小的整数。
现在,当您使用,
scanf(“%s”)和&words[i])您正在尝试将字符串读入正确的每个整数位置。这就是即使输入字符串也只能存储第一个字符的原因。

int words[]
words是一个整数数组,只能保存指定大小的整数。
现在,当您使用,
scanf(“%s”)和&words[i])您正在尝试将字符串读入正确的每个整数位置。这就是即使输入字符串也只能存储第一个字符的原因。

int words[]
words是一个整数数组,只能保存指定大小的整数。
现在,当您使用,
scanf(“%s”)和&words[i])您正在尝试将字符串读入正确的每个整数位置。这就是为什么即使输入字符串,您也只能存储第一个字符。

为什么
计数器
是一个函数参数,如果在函数中有两行您用用户的输入覆盖了它,那么无论如何我会保留一个记录,以便在另一个函数中再次使用:)好的-也许最好将计数传递回
main
通过return语句,因此在main中可以将此函数的返回值传递给另一个函数function@TimCastelijns“你用用户的输入覆盖它”--这不会发生。。。只更改计数器指向的值,而不更改计数器本身。虽然返回计数器值比传递指向它的指针更干净(除非有多个返回值)。@JimBalter
只有计数器指向的值被更改了
。我以为他想给计数器传递一个值作为参数,我不知道这仅仅是为了跟踪它以后再使用它为什么
counter
是一个函数参数,如果函数中有两行你用用户的输入覆盖了它,我会保存一个记录,以便在另一个函数中再次使用:)好的-也许最好通过返回语句将计数传递回
main
,因此,主要是将这个函数的返回值传递给另一个函数function@TimCastelijns“你用用户的输入覆盖它”--这不会发生。。。只更改计数器指向的值,而不更改计数器本身。虽然返回计数器值比传递指向它的指针更干净(除非有多个返回值)。@JimBalter
只有计数器指向的值被更改了
。我以为他想要