dimanche 10 septembre 2017

Why is my code outputting random numbers even though they are just counts?

I am starting to learn c. I am trying to make a code that will count the amount of a's and A's in a sentence but the code gives me random numbers every time it is executed even if it is the same sentence.

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

int main()
{
    char words[10000000000];
    int i;
    int acount = 0;
    int Acount = 0;
    char A[0]="A";
    char a[0]="a";
    printf("Input your sentence to be counted.");
    scanf("%s",words);
    printf("%s",words);
    for (i=0;i<=sizeof(words);i++)
    {
        if (words[i]==a[0]){
            acount++;
        }else if (words[i]==A[0]){
            Acount++;
        }
    }
    printf ("\nThe number of A's is %i. The number of a's is %i.",Acount,acount);
    return 0;

}




Aucun commentaire:

Enregistrer un commentaire