[Show all top banners]

comingsoon

More by comingsoon
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Discussion Refresh page to view new replies
 How to count line in c?
[VIEWED 1043 TIMES]
SAVE! for ease of future access.
Posted on 10-25-13 4:48 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

I try this way and good fail many time. Any help, will be celebrate with grate appreciation. Thanks. I also try fgets() same way but didn't work as well.
int line_count ()
{
    FILE * fp;         // file open from here.
    int i=0;
    int c;
    if ((fp = fopen ("file.txt", "a")) != NULL){
        while ((c=fgetc(fp))!=EOF)
        {
            if (c=='\n') {
                i++;
            }
           
        }
        fclose(fp);
    }
    else printf(" Error.\n");
    return i;
}


Last edited: 25-Oct-13 04:52 PM
Last edited: 25-Oct-13 04:54 PM

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
Wedding Costs in Nepal ? Party, Band Baaja !!!!???
Returning to Nepal
TPS FEDERAL NOTICE
TPS EAD rejected: Help
गुन्द्रुक को झोलाँ.......
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters