简体   繁体   English

错误:预期 ')' 在 ';' 之前 c 程序上显示的令牌,用于检查字符串是否为回文

[英]error: expected ')' before ';' token showing on c program to check if a string is palindrome or not

isn't my assignment,condition and updation in my for loop correct?,its showing the error on that line我的 for 循环中的分配、条件和更新不正确吗?它显示了该行的错误

void main()
{  int i,j,n;
   char a[10];
   printf("\t\tPROGRAM TO CHECK IF A STRING IS PALINDROME OR NOT");
   printf("\n\t\t-----------------------------------------------");
   printf("\nEnter the string: ");
   gets(a);
   n=strlen(a);
   for(i=0;j=n-1;i<=j;i++;j--){
    if(toupper(a[i])!=toupper(a[j])){
        printf("The string is not palindrome");
        break;
    }
   }
   if(i==j){
    printf("\nThe string %s is a palindrome",a);
   }
   getch();

}

Your problem is that the line for(i=0;j=n-1;i<=j;i++;j--){ has too may semicolons in it!您的问题是for(i=0;j=n-1;i<=j;i++;j--){行中的分号太多!

Semicolons separate statements and for takes only three such.分号分隔语句for只需要三个这样的语句。 To put two (or more) expressions in the same statement, separate them with commas, as follows: for(i=0, j=n-1; i<=j; i++, j--){要将两个(或多个)表达式放在同一个语句中,用逗号分隔它们,如下所示: for(i=0, j=n-1; i<=j; i++, j--){

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM