mercredi 9 novembre 2016

Displaying lines with given number of characters

I have written such a program which suppose to returns lines which are containing at least 11 characters and 4 digits. I messed up something with types of variables I guess but I cant figure out how should I fix it.

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


int main()
{
    char line[200];
    char *temp[200];
    int i = 0, k=0;

    printf("Enter a string: \n");
    while(fgets(line, sizeof(line),stdin))
    {
        int numberAlpha = 0;
        int numberDigit = 0;
        int i;
        for(i=0; i<strlen(line); i++){
            if(isalpha(line[i])) numberAlpha++;
            else if(isdigit(line[i])) numberDigit++;
        }

        if(numberAlpha+numberDigit>10 && numberDigit>3){
            temp[i]=line;
            i++;
        }
    }
    while(temp[k]!='\0'){
        printf("%s", temp[k]);
        k++;
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire