When compiled it is showing warning:cannot find entry symbol Rrors;defaulting to 0000000000400590

元气小坏坏 提交于 2019-12-23 06:09:37

问题


the while loop is not working here.there is no compilation error and the print statement is also getting executed in the beggining.the code works fine without the while loop.the code is to print the most repeating letter in a string and the number of times it is repeated

#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);
   }

}

回答1:


After the following line is executed,

scanf("%d",&t);

the newline character is still left in the input stream. The next call to gets ends up reading just the newline.

You need to add code to ignore the rest of the line after readning t.

scanf("%d",&t);

// Ignore the rest of the line from the input stream.
char c;
while ( (c = getchar()) != '\n' && c != EOF);

Also, don't use gets.

Further reading: Why is the gets function so dangerous that it should not be used?.

Use fgets instead.




回答2:


According to what you mentioned, while loop works fine and just use scanf() in place of gets()(Don't use gets()) and then printf() will also be executed after loop.




回答3:


You can also ask directly to your gcc compiler:

gcc test.c -o test.x -std=c99 -Wall -Wextra

And to be sure, try other options: -std=gnu99, -std=gnu89, -std=c89, and my preferred:

gcc test.c -o test.x -Wall -Wextra -ansi -pedantic-errors -O0


来源:https://stackoverflow.com/questions/31167941/when-compiled-it-is-showing-warningcannot-find-entry-symbol-rrorsdefaulting-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!