Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.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
C++ GCC 3.3.4中的字符数组声明错误 int main(){ charb[100]; 对于(inti=1;i_C++_C_Gcc_Gcc Warning - Fatal编程技术网

C++ GCC 3.3.4中的字符数组声明错误 int main(){ charb[100]; 对于(inti=1;i

C++ GCC 3.3.4中的字符数组声明错误 int main(){ charb[100]; 对于(inti=1;i,c++,c,gcc,gcc-warning,C++,C,Gcc,Gcc Warning,#include <cstdio> #include <stdlib.h> using namespace std; int p[100], b, bc; char bb[100]; int main () { printf("Enter Count : "); scanf ("%d", &bc); for (b = 1; b <= bc; b++ ) { printf("E

#include <cstdio>
#include <stdlib.h>

using namespace std;


int p[100], b, bc;
char bb[100];

int main () {


        printf("Enter Count : ");
        scanf ("%d", &bc);
        for (b = 1; b <= bc; b++ ) {
            printf("Enter a char and integer: ");
            scanf ("%c%*c %d", &bb[b-1], &p[b-1]);
            printf ("\n Your Entries =>  %c,  %d", bb[b-1], p[b-1]);
        }


    return 0;
}

scanf()

为了避免这种情况,我使用了%*c
scanf(“%c%*c%d%*c”、&bb[b-1]、&p[b-1]);

谢谢大家

scanf("%c", &b[i]);

哦!是C++。<强>我的答案不考虑我不知道的C++细节。< /强> < /P>

using namespace std;
如果可以避免使用全局变量,代码将更容易处理

int p[100], b, bc;
char bb[100];
scanf()
是出了名的难以正确使用。
无论如何,
“%d”
转换说明符已经丢弃了空白,这样您就可以删除奇怪的内容;而且上次调用
scanf
时还有一个ENTER挂起。在格式字符串中使用空格可以去除它

            printf("Enter a char and integer: ");
            // scanf ("%c%*c %d", &bb[b-1], &p[b-1]);

<强> >有趣>

这不是你在C或C++中写for循环的方法:只是展示如何,没有别的…..)你为什么要关闭这个?你的声明是可以的。试试<代码> char b(100);fGET(b,sisiof b,STDIN);< /Cord>…和后真正可编译(或非常接近编译)代码。不太清楚为什么这是如此严重的否决/投票关闭…不,现在没有错误,但当我试图打印它不显示时,我需要“%c%*c”这是因为我想在每个字符后读取一个整数,否则换行符条目将中断execution@coderex:是的,您可能需要根据您的具体要求修改此项。我上面的代码片段是为了演示提供地址的需要。@coderex:
printf(“%c\n”,b[i]”)
@coderex:除非你提供一些实际的代码,否则我帮不了你。8年后,我使用C/C++。我建议你坚持使用
C
C++
(或
C
,或
D
,…)中的一种。不要尝试编写多语言源文件。请看我的答案……但是
scanf(“%C%D”、&bb[b-1]、&p];
“有效”,而且对眼睛和大脑更容易。
using namespace std;
int p[100], b, bc;
char bb[100];
int main () {


        printf("Enter Count : ");
        scanf ("%d", &bc);
        for (b = 1; b <= bc; b++ ) {
            printf("Enter a char and integer: ");
            // scanf ("%c%*c %d", &bb[b-1], &p[b-1]);
            scanf (" %c%d", &bb[b-1], &p[b-1]);
            printf ("\n Your Entries =>  %c,  %d", bb[b-1], p[b-1]);
        }


    return 0;
}