编译时显示 warning:cannot find entry symbol Rrors;defaulting to 0000000000400590
When compiled it is showing warning:cannot find entry symbol Rrors;defaulting to 0000000000400590
while 循环不工作 here.there 没有编译错误并且打印语句也在 beggining.the 代码中执行,没有 while loop.the 代码打印字符串中重复次数最多的字母及其重复次数
#include <stdio.h>
#include <string.h>
int main(void)
{
int t;
int tempC;
scanf("%d",&t);
while ( (tempC = getchar()) != '\n' && tempC != EOF );
while(t--)
{
char c[100];
char r='z';
int i,j=0,count,a,k,amx;
gets(c);
k=strlen(c);
for(i=0,amx=1;i<k;i++)
{
if(c[i]!=0)
{
for(j=0,count=1;j<k;j++)
{
if(c[i]==c[j])
{
if(i!=j)
{
count++;
c[j]=0;
}
a=count;
if(a>amx||(a==amx&&(c[i]<r)))
{
amx=a;
r=c[i];
}
}
}
}
}
printf("%d %c\n",amx,r);
}
}
下面一行执行后,
scanf("%d",&t);
换行符仍然留在输入流中。对 gets
的下一次调用最终只读取换行符。
您需要添加代码以在阅读 t
后忽略该行的其余部分。
scanf("%d",&t);
// Ignore the rest of the line from the input stream.
char c;
while ( (c = getchar()) != '\n' && c != EOF);
此外,不要使用 gets
。
延伸阅读:Why is the gets function so dangerous that it should not be used?.
改用fgets
。
根据您的说法,while 循环工作正常,只需使用 scanf() 代替 gets()(不要使用 gets()),然后 printf() 也会在循环后执行。
您也可以直接询问您的 gcc compiler
:
gcc test.c -o test.x -std=c99 -Wall -Wextra
当然,请尝试其他选项:-std=gnu99
、-std=gnu89
、-std=c89
,我的首选:
gcc test.c -o test.x -Wall -Wextra -ansi -pedantic-errors -O0
while 循环不工作 here.there 没有编译错误并且打印语句也在 beggining.the 代码中执行,没有 while loop.the 代码打印字符串中重复次数最多的字母及其重复次数
#include <stdio.h>
#include <string.h>
int main(void)
{
int t;
int tempC;
scanf("%d",&t);
while ( (tempC = getchar()) != '\n' && tempC != EOF );
while(t--)
{
char c[100];
char r='z';
int i,j=0,count,a,k,amx;
gets(c);
k=strlen(c);
for(i=0,amx=1;i<k;i++)
{
if(c[i]!=0)
{
for(j=0,count=1;j<k;j++)
{
if(c[i]==c[j])
{
if(i!=j)
{
count++;
c[j]=0;
}
a=count;
if(a>amx||(a==amx&&(c[i]<r)))
{
amx=a;
r=c[i];
}
}
}
}
}
printf("%d %c\n",amx,r);
}
}
下面一行执行后,
scanf("%d",&t);
换行符仍然留在输入流中。对 gets
的下一次调用最终只读取换行符。
您需要添加代码以在阅读 t
后忽略该行的其余部分。
scanf("%d",&t);
// Ignore the rest of the line from the input stream.
char c;
while ( (c = getchar()) != '\n' && c != EOF);
此外,不要使用 gets
。
延伸阅读:Why is the gets function so dangerous that it should not be used?.
改用fgets
。
根据您的说法,while 循环工作正常,只需使用 scanf() 代替 gets()(不要使用 gets()),然后 printf() 也会在循环后执行。
您也可以直接询问您的 gcc compiler
:
gcc test.c -o test.x -std=c99 -Wall -Wextra
当然,请尝试其他选项:-std=gnu99
、-std=gnu89
、-std=c89
,我的首选:
gcc test.c -o test.x -Wall -Wextra -ansi -pedantic-errors -O0