-3

Hi i am looking for program that reads and counts chars, lines(rows), numbers and other characters from file test.txt and puts results on screen. Thank you for help I am not a programmer and dont want to do anything with it just need it now thank you.

4
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by kiran002
-1

Ya.. the above link provides you all.. for just knowing you could refer file handling operations in any c language books....

-1
#include<stdio.h>
int main(void) {
    FILE *fp = fopen("test.txt","r");
    char c;
    int lines,numbers,others,temp;
    lines=numbers=others=0;
    while((c=getc(fp))!=EOF) {
        temp=c;
        if(temp>=48 && temp<=57)
            numbers++;
        else if(c=='\n')
            lines++;
        else
            others++;
    }
    printf("The total number of chars : %d\nThe total number of lines : %d\nThe total number of digits : %d\nThe total number of other characters: %d",numbers+lines+others,lines+1,numbers,others);
    getchar();
    getchar();
}

hope it helps

Votes + Comments
Don't give away complete code
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.