Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why in this code sterlen() is always 0.

0 votes
asked Jun 28, 2019 by Hritik
int a[26],l=3 ,as,i;
    
char w[10];

    for ( i=0;i<26; i++)
    {
        scanf("%d",&a[i]);
    }
    gets(w);

     
    while(w[i]!='\0')
    { as=w[i];
        if(l<a[as-97])
        l=a[as-97];
    }
    
    printf("%d",strlen(w)*l);
    return 0;

1 Answer

0 votes
answered Jul 6, 2019 by anonymous

In the above program the statement while(w[i]!='\0') is clearly telling that the w[i] is not a null character. then it contains some value between alphabetic range. so as has some number above 60 and below 97. so it will take negative index a[-x]  and that value is equal to 0 by default and it is always less than 'l. 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...