[Show all top banners]

comingsoon

More by comingsoon
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 How to count line in c?
[VIEWED 2177 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 30 days
Recommended Popular Threads Controvertial Threads
What stocks to buy -- Any recommendation
निगुरो थाहा छ ??
Conservative discussions
हेरेको तिमीलाइ आँखाले हैन।
Pfizer Chief scientist says those who took vaccine will die in 3 years
म अम्रिकामा adjust हुन सकिन :(
KP and PK
प्रचाण्डको लड्डु
5 questions to ask your friends who plan to get the Covid vaccine
hello hello
Well this is fked #TPS status doesn’t allow application for Green Cards
🙏 दलाल स्ट्रिट 🙏
हेत्छाकुप्पाको कथा (नेपाली लोक कथा)
Going back home After 18 years
Health insurance for parents over 65 years
RIP Ujjwal Thapa - US Return Nepali politician
What car to buy?
अमेरिकामा हुनेले भोट गरे हुने ...
नेपाली नाता
Congratulations to Nimsdai and the team for a world record summit of K2 in the winter!
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