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.

Recommended Answers

All 3 Replies

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

#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

commented: Don't give away complete code -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.