TOPIC

Compilation error

SHUVRA ADITYA (IIT_NSTU) (͡ ° ͜ʖ ͡ °) asked 1 year ago

#include<stdio.h>
int main()
{
    int T, key;
    scanf("%d",&T);
    char ch[52];

    for(int i=0; i<T; i++)
    {
        getchar();
        scanf("%[^\n]s",&ch);
        scanf("%d",&key);
        int j=0;
        while(ch[j]!='\0')
        {
            if(ch[j]-key<65)
                printf("%c",ch[j]-key+26);
            else
                printf("%c",ch[j]-key);
            j++;
        }
        printf("\n");
        ch[0]='\0';
    }
    return 0;
}

Why my above code giving Compailation error in c lannguage. But it get accepted in c++17. What is the reason?

Remember not post solutions. Your post may be reviewed by our moderators.

  • Rahilly Machado replied 1 year ago

    In line 8, the declaration of variable "i" must be made outside the for loop. This, as far as I know, is only required to submit codes in c, since the version used by the site does not support the form you used. Correction:

    int i;
    for(i=0;i<T;i++)
    {
      ...
    }