C_130 C Program to Count no of Lines in a Text File | File Handling in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2025

ความคิดเห็น • 94

  • @harispap5180
    @harispap5180 2 ปีที่แล้ว +34

    Tomorrow I'm writing my exam in data structures in c language, Jenny really helped me understand merge sort...wish my luck guys, i hope you do well in your exams too.

  • @marbles5590
    @marbles5590 2 ปีที่แล้ว +50

    For the assignment:
    #include
    #include
    int main()
    {
    FILE *fp = NULL;
    int count = 1, charac=0;
    char ch;
    fp = fopen("abc.txt", "r");
    if(fp==NULL)
    {
    printf ("ERROR");
    exit(1);
    }
    while((ch=fgetc(fp))!=EOF)
    {
    if(ch=='
    ')
    {
    count++;
    }
    else
    {
    charac++;
    }
    }
    fclose(fp);
    printf ("
    Count: %d
    ", count);
    printf ("Number of Characters: %d", charac);
    return 0;
    }
    The variable charac is for the number of characters mam. :))

    • @farzanaashraf8136
      @farzanaashraf8136 2 ปีที่แล้ว +5

      We can simply write charac++ without else block.

    • @farzanaashraf8136
      @farzanaashraf8136 2 ปีที่แล้ว +1

      Hey mera characters count galt a rha kya bta sakt k newline (
      ) b characters ,ma count ho ga?

    • @marbles5590
      @marbles5590 2 ปีที่แล้ว +2

      @@farzanaashraf8136 yeah i know, that's just the way how i do my code neatly

    • @farzanaashraf8136
      @farzanaashraf8136 2 ปีที่แล้ว

      @@marbles5590 Nice

    • @millicentwamuru314
      @millicentwamuru314 2 ปีที่แล้ว

      but in your program it doesn't account for the '
      ' or aren't we supposed to include them

  • @hariparuchuru3858
    @hariparuchuru3858 2 ปีที่แล้ว +24

    Program to count No of characters in file
    This program also counts new line character also.
    #include
    #include
    void main()
    {
    FILE *fp = NULL;
    char ch;
    int LineCount =1, charcount =0;
    fp = fopen("abc.txt","r");
    if (fp == NULL)
    {
    printf(" NO FIlE");
    exit(1);
    }
    while((ch = fgetc(fp))!= EOF)
    {
    charcount++;
    if(ch == '
    ')
    {
    LineCount++;
    }
    }
    fclose(fp);
    printf("The LineCount and charcount is %d and %d", LineCount, charcount);
    }

    • @gouravchandel8107
      @gouravchandel8107 2 ปีที่แล้ว +1

      But i guss it will take
      also as a character but we don't want to count
      as a character.

    • @hariparuchuru3858
      @hariparuchuru3858 2 ปีที่แล้ว +5

      If you don't want to add new line
      Then make a if condition for character count also
      If(ch != '
      ')
      Charcount++;
      Then you won't count new line

    • @ahmed.saa7
      @ahmed.saa7 2 ปีที่แล้ว +2

      @@gouravchandel8107 you can use else statement because if statement will only run when there is
      so it won't count
      because at that time only if statement will run and in other cases else will run and it will count number of characters in file

    • @tejhimanshu
      @tejhimanshu 2 ปีที่แล้ว +1

      correct for line count not for char count
      when 2 or 3 lines are empty, only '
      ', then it will count that character also
      use charcount-LineCount for calculating characters

  • @SSingh_here
    @SSingh_here 3 หลายเดือนก่อน +1

    just add int len=ftell(fp); after the while loop it will give the length of file

  • @naveen5285
    @naveen5285 2 ปีที่แล้ว +2

    Mam u r simply awesome, u made C easy and understanding, thank you so much

  • @sahilmd178
    @sahilmd178 ปีที่แล้ว +3

    assignment:
    #include
    #include
    int main(){
    FILE *fp=NULL;
    char character;
    int count=1;
    int ch=0;
    fp=fopen("countline.txt","r");
    if(fp==NULL){
    printf("Error in creating file");
    exit(1);
    }
    while((character=fgetc(fp))!=EOF){
    if(character=='
    '){
    count++;
    }
    // }
    //If u want to count characters with out spaces
    else if(character!=' '){
    ch++;
    }
    }
    printf("NO of lines:%d
    ",count);
    printf("No of characters:%d",ch);
    fclose(fp);
    return 0;
    }//hope this helped u😅

  • @jony-s5m
    @jony-s5m 2 ปีที่แล้ว +2

    Mam your video's are so much help full to. TQ mam for helping us 🌟

  • @mohankonduru6301
    @mohankonduru6301 2 ปีที่แล้ว +3

    Mam plzz try start any other language like Java, or python like this , coz your teaching style too good mama so

  • @jaxonffmgamer3318
    @jaxonffmgamer3318 5 หลายเดือนก่อน +1

    Mam please help me to prepare this program:
    Q. Write a program to copy all the contents of one file to another file that stores all the lower-case alphabets into lower.txt
    upper-case alphabets into upper.txt
    digits into digit.txt
    rest of characters into rest.txt .

  • @pinki256
    @pinki256 5 หลายเดือนก่อน +1

    mam please help me to prepare this program:
    Q. Write a program to copy all the contents of one file to another file that stores all lower-case alphabets into lower.txt
    upper-case alphabets into upper.txt
    digits into digit.txt and rest of characters into rest.txt .

  • @parisa9374
    @parisa9374 2 ปีที่แล้ว +3

    Hello Jenny, May you please make videos on Command Line Arguments too? Thank you and you are an awesome and cool TECH LADY!

  • @Ankit-vp7nt
    @Ankit-vp7nt 2 ปีที่แล้ว +2

    Mam please make one small video to visual studio code (c programs setup).

  • @87shortz
    @87shortz ปีที่แล้ว +1

    Mam kal exam h aaj raat ko pointer ki video one shot video upload honi chahiye

  • @divyanshbalodhi5642
    @divyanshbalodhi5642 2 ปีที่แล้ว +1

    Mazaa aa gayaa ma'am ji🙏

  • @_master_op_
    @_master_op_ 2 ปีที่แล้ว +8

    CODE for counting the characters :
    #include
    #include
    void main()
    {
    FILE *fp=NULL;
    char c;
    int n=0;
    fp=fopen("abc.txt","r");
    if(fp==NULL)
    {
    printf("no file");
    exit(1);
    }
    //while((c=fgetc(fp))!=EOF)
    for(c=fgetc(fp);c!=EOF;c=fgetc(fp))
    {
    n++;
    }
    fclose(fp);
    printf("Nmber of characters are : %d
    ",n);
    }

    • @satyabrata2129
      @satyabrata2129 2 ปีที่แล้ว +2

      Bro i want to just friendship with you for coding
      Can you be my friend..

    • @_master_op_
      @_master_op_ 2 ปีที่แล้ว

      @@satyabrata2129 yeah why not😇

    • @_master_op_
      @_master_op_ 2 ปีที่แล้ว +1

      @@satyabrata2129 sid_sidharth_19

    • @_master_op_
      @_master_op_ 2 ปีที่แล้ว

      Id of instagram

    • @tejhimanshu
      @tejhimanshu 2 ปีที่แล้ว

      correct for line count not for char count
      when 2 or 3 lines are empty, only '
      ', then it will count that character also
      consider it also

  • @__SHRAVANIPACHUNURI
    @__SHRAVANIPACHUNURI 2 ปีที่แล้ว +2

    Mam one doubt..that in this program how the cursor is incremented by 1 in while loop mam

  • @faisalwani8055
    @faisalwani8055 2 ปีที่แล้ว +1

    Mam.total kitne tutorials hai..c..k????

  • @AmarSingh-ur5wq
    @AmarSingh-ur5wq 2 ปีที่แล้ว +1

    Can you make video of string, array and char related concepts , how to play with this

  • @devendradangare440
    @devendradangare440 2 ปีที่แล้ว +1

    we have't increased the file pointer but also how its taking next character ?

  • @rajudr3286
    @rajudr3286 2 ปีที่แล้ว +1

    Delete,sort,word replace related programs mam in file handling

  • @Sindhu.M.V
    @Sindhu.M.V 11 หลายเดือนก่อน

    Mam please do the chapter text processing & pattern searching

  • @Beyondimagination1
    @Beyondimagination1 2 ปีที่แล้ว

    Mam if possible then u teach us on an compiler extension...like as VS Code , Dev or anything. Which u like most ..

  • @souravmete8809
    @souravmete8809 2 ปีที่แล้ว

    mam can you make a vedio on ...
    1. write a program to find and replace a word in a File by another given word

  • @dineshkantineni6232
    @dineshkantineni6232 2 ปีที่แล้ว +1

    How to delete a particular line in a file

  • @greenhomemusic3196
    @greenhomemusic3196 2 ปีที่แล้ว +1

    Please tell a program for sudo code...please mam🙏🙏

  • @uniquegaming1487
    @uniquegaming1487 2 ปีที่แล้ว +3

    I don't know what r u teaching in your videos 😂
    But I'm just watching videos again and again
    Your explanation is going better day by day so
    Just Thanks

  • @vinayakghodke9871
    @vinayakghodke9871 2 ปีที่แล้ว +13

    for no of characters:
    #include
    #include
    void main()
    {
    FILE *fp=NULL;
    fp=fopen("abc.txt","r");
    int count=1;
    char ch;
    char str[50];
    if(fp==NULL)
    {
    printf("error");
    exit(1);
    }
    // rewind(fp);
    while((ch=fgetc(fp))!=EOF)
    {
    if(ch=='
    ')
    {
    count++;
    }
    }
    rewind(fp);
    fseek(fp,0,SEEK_END);
    printf("No of characters=%d
    ",ftell(fp));
    fclose(fp);
    printf("No of lines=%d",count);
    }

    • @satyabrata2129
      @satyabrata2129 2 ปีที่แล้ว +1

      Without rewind() it also cam be possible.... ..
      It's correct or not..

    • @mrinaltyagi2206
      @mrinaltyagi2206 2 ปีที่แล้ว

      @@satyabrata2129 yes without rewind it can be done

    • @mrinaltyagi2206
      @mrinaltyagi2206 2 ปีที่แล้ว

      @@satyabrata2129 this solution provided vinayak is incorrect

    • @tejhimanshu
      @tejhimanshu 2 ปีที่แล้ว

      not correct

  • @sriratnaforlife1132
    @sriratnaforlife1132 2 ปีที่แล้ว +1

    Mam please reply
    I know nothing about coding and programming or algorithm
    How to start I learning for beginner
    Step to step
    🙏🙏🙏

  • @nageshgour3148
    @nageshgour3148 2 ปีที่แล้ว +1

    Mam please make video about how to get job after graduation

    • @vinaygupta8532
      @vinaygupta8532 ปีที่แล้ว

      Bhai pata chal gya hoto mujhe bhi bata de ....

  • @mgjdb
    @mgjdb 2 ปีที่แล้ว

    Mam please do important programs for drives

  • @hardiksharma5574
    @hardiksharma5574 ปีที่แล้ว +3

    #include
    #include
    #include
    int main(int argc, char const *argv[])
    {
    FILE *fp;
    fp = fopen("abc.txt", "r");
    char ch;
    int count = 1;
    int k = 0;
    while ((ch = fgetc(fp)) != EOF)
    {
    if (ch == '
    ')
    {
    count++;
    }
    else
    {
    k++;
    }
    }
    fclose(fp);
    printf("%d
    ", count);
    printf("%d
    ", k);
    return 0;
    }

  • @luckysgallery4938
    @luckysgallery4938 2 ปีที่แล้ว

    mam please can you explain how to print a specific line from a file (file handling)

  • @cinexstudio0
    @cinexstudio0 6 หลายเดือนก่อน

    Write a C program to replace vowels in a text file with character ‘x’

  • @saifali-zk6yp
    @saifali-zk6yp 2 ปีที่แล้ว

    Big fan ma'am

  • @sangeetharam1382
    @sangeetharam1382 2 ปีที่แล้ว

    Useful mam Thankyou

  • @faisalwani8055
    @faisalwani8055 2 ปีที่แล้ว +2

    Mam.big fan from Kashmir....

  • @dineshkantineni6232
    @dineshkantineni6232 2 ปีที่แล้ว

    how to sort a given file

  • @r.k8895
    @r.k8895 2 ปีที่แล้ว

    Thank you very much mem.

  • @87shortz
    @87shortz ปีที่แล้ว

    Kl exam hai apki wishes chaiye

  • @pkmcdry9586
    @pkmcdry9586 2 ปีที่แล้ว

    Beautiful

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 ปีที่แล้ว

    Thanks mam

  • @57samarthhatte82
    @57samarthhatte82 2 ปีที่แล้ว

    wel done mam

  • @schoollife1284
    @schoollife1284 2 ปีที่แล้ว +2

    Ma'am aaj tho rest karna dho plzz

    • @_kucial_
      @_kucial_ 2 ปีที่แล้ว +1

      🤣🤣🤣

  • @tunahankarali6917
    @tunahankarali6917 ปีที่แล้ว

    THERE ARE MANY ADVERTİSEMENTS İT İS ANNOYİNG WHİLE I AM STUDYİNG

  • @kdnation5629
    @kdnation5629 2 ปีที่แล้ว

    If you tech in hindi language then more people take advantage of your videos.. You know very well that most of the people of india doesn't know English..India you know very well also that we are not sons of english

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 ปีที่แล้ว +1

    Assignment:
    Number of lines and characters:
    #include
    #include
    int main(void)
    {
    FILE *fp = NULL;
    int count = 1; // Initialize count to 1 for the first line
    char ch;
    fp = fopen("abc.txt", "r");
    if (fp == NULL)
    {
    printf("Error, file does not exist
    ");
    exit(1);
    }
    while ((ch = fgetc(fp)) != EOF)
    {
    if (ch == '
    ')
    {
    count++;
    }
    }
    fseek(fp,0,SEEK_END);
    printf("No of characters is: %d
    ",ftell(fp));
    printf("No of lines are: %d
    ", count);
    fclose(fp);
    }

  • @jitendraprajapat1192
    @jitendraprajapat1192 2 ปีที่แล้ว

    Mem aap ko kya pdate ho

  • @sivapavanchowdary3755
    @sivapavanchowdary3755 2 ปีที่แล้ว

    Ma'am please explain about python 🙏

  • @medasridhanya6246
    @medasridhanya6246 2 ปีที่แล้ว

    Godess 🙏 tq for teaching it is easily understandable

  • @priyanshubisht8326
    @priyanshubisht8326 2 ปีที่แล้ว

    Tower of Hanoi

  • @Rahul-pz9oe
    @Rahul-pz9oe ปีที่แล้ว

    Hindi me praiyye na mam smjh me nhi aata h😢

  • @howtodo2322
    @howtodo2322 2 ปีที่แล้ว

    she getting so cute

  • @santoshkumarmahanty2048
    @santoshkumarmahanty2048 2 ปีที่แล้ว

    Mamm love you so much.....u r my crush mamm

  • @Hemanthrr7
    @Hemanthrr7 2 ปีที่แล้ว

    i love you mdama i will die for you please accept my love ❤😘

  • @MARCO__NG
    @MARCO__NG หลายเดือนก่อน

    😒😮‍💨😮‍💨🤥🤥😒

  • @p.adityapatro8673
    @p.adityapatro8673 2 ปีที่แล้ว

    I am first

  • @KRISHNA_VLOGS49
    @KRISHNA_VLOGS49 2 ปีที่แล้ว

    Im first

  • @mohanmedmamman7900
    @mohanmedmamman7900 2 ปีที่แล้ว

    Mam do you have a sister 🥰

  • @robertmaina4807
    @robertmaina4807 ปีที่แล้ว +2

    #include
    #include
    int main()
    {
    FILE *fp;
    int count = 1;
    int c;
    char ch;
    fp = fopen("abg.txt","r");
    if(fp == NULL)
    {
    printf("Error opening file
    ");
    exit(1);
    }
    while((ch = fgetc(fp)) !=(EOF))
    {
    if(ch == '
    ')
    {
    count++;
    }
    }
    fseek(fp, 0, SEEK_END);
    c = ftell(fp);
    printf("The number of characters are %d
    ", c);
    fclose(fp);
    printf("The lines are %d
    ", count);
    return 0;
    }

  • @Antik-n1b
    @Antik-n1b 4 หลายเดือนก่อน

    #include
    #include
    void main()
    {
    char ch;
    int count = 0;
    int k = 1;
    FILE *fp = NULL;
    fp = fopen("abc.txt", "r");
    if (fp == NULL)
    {
    printf("Error");
    exit(1);
    }
    while (!feof(fp))
    {
    ch = fgetc(fp);
    if (ch == '
    ')
    k = k + 1;
    if ((ch != '
    ') && (ch != ' '))
    count = count + 1;
    }
    fclose(fp);
    printf("No. of characters = %d
    ", count - 1);
    printf("No. of lines = %d", k);
    }

  • @md_mazharul_haque
    @md_mazharul_haque 2 ปีที่แล้ว

    𝕋𝕙𝕒𝕟𝕜 𝕪𝕠𝕦 ❤ 𝕞𝕖𝕞