no. of digits and special character

 #include <stdio.h>



int main()

{

    FILE *file;

    char filename[100];

    char ch;

    printf("Enter The Filename: ");

    scanf("%s", filename);


    file = fopen(filename, "r");

    if (file == NULL)

    {

        printf("Error in opening the file\n");

        return 1;

    }


    int number = 0;

    int spchar = 0;


    while ((ch = fgetc(file)) != EOF)

    {

        if (ch >= '0' && ch <= '9')

        {

            number++;

        }

        else if (ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '_' || ch == '^' || ch == '!')

        {

            spchar++;

        }

    }


    printf("count of numbers: %d\n", number);

    printf("count of special characters: %d\n", spchar);


    fclose(file);

    return 0;

}

Comments