TOPIC

Problem with code

Michel Guilhen asked 9 months ago

Code finishes after number of test cases input

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

struct letras{char letra;
                int indice;};

int main()
{
    int i, n, maior=-1;
    char string[201];
    struct letras abc[25];

    for(i=0; i<26; i++)
        abc[i].letra = 'a' + i;

    scanf("%d", &n);

  for (i=0; i<n; i++)
    {
        for(i=0; i<26; i++)
            abc[i].indice = 0;

        scanf("%[^\n]", string);

        for(i=0; string[i] != '\n'; i++)
        {
            if((abc[i].letra >= 'A' && abc[i].letra <= 'Z') || (abc[i].letra >= 'a' && abc[i].letra <= 'z'))
            {
                if(string[i] == 'A' || string[i] == 'a')
                {
                    abc[0].indice += 1;
                    continue;
                }
                if(string[i] == 'B' || string[i] == 'b')
                {
                    abc[1].indice += 1;
                    continue;
 // Until letter  Z or z //
                }
            }       
        }
        for (i=0; i<26; i++)
            if(abc[i].indice > maior)
                maior = abc[i].indice;

        for (i=0; i<26; i++)
            if(abc[i].indice == maior)
                printf("%c", abc[i].letra);

        printf("\n");
    }
    return 0;
}

This topic has not been answered yet. Be the first!

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