#29: C File Handling | C Programming for Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024
  • #29: C File Handling | C Programming for Beginners
    In this video, we will learn to work with files in C programming. More specifically, we will learn to perform file operations like read content from the file, write content to file.
    In C programming, there are usually 3 steps involved while working with files:
    1. Open a file
    2. Perform File Operation
    3. Close the file
    We will learn all about the file handling with examples in the video.
    Sign Up to get 50% off with this link: app.programiz....
    This video is a part of our C Programming video series: • #1: Getting Started wi...
    ~
    Resources:
    C Online Compiler: www.programiz....
    Github File: github.com/pro...
    C (title) Tutorial (text-based tutorial): www.programiz....
    Timestamps:
    00:30 - Open a File
    04:38 - Read File Content
    07:00 - Closing File
    08:02 - Write Content to File
    11:30 - Programming Task
    11:57 - Quiz
    ~
    Revise your learning using our C App
    Download here for Android: bit.ly/3upaInx
    Download here for iOS: apple.co/3EZLtNq
    Find Programiz elsewhere:
    Programiz PRO: programiz.pro/
    Website: www.programiz.com
    Discord: / discord
    Facebook: / programiz
    Instagram: / _programiz
    LinkedIn: / programiz
    Twitter: / programiz
    #programiz #cprogramming #C #filehandling #readfile #closefile #write

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

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

    🔥Finding it Damn Hard to Understand C Programming?
    Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT!
    Try Programiz PRO for Free: bit.ly/master-c-programming

  • @shivamchakraborty9573
    @shivamchakraborty9573 ชั่วโมงที่ผ่านมา

    Thank you so much for this, helped me in my project like an angel!!

  • @ezrakim1323
    @ezrakim1323 ปีที่แล้ว +73

    If u don't want to remove all the previous contents of the file when u write in it, u can use append instead.
    The syntax is
    fptr = fopen("text.txt", "a");

    • @kartikpintu
      @kartikpintu 6 หลายเดือนก่อน +2

      I was wondering about this. Thanks

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

      Thank u bro🎉

  • @rogue9433
    @rogue9433 3 หลายเดือนก่อน +5

    the answer's B! Also, this vid's amazing; i got my programmin exam in a few hours, thank a bunch!

  • @limitess9539
    @limitess9539 ปีที่แล้ว +17

    If you create a file via write mode, or append mode, try naming your file aux
    FILE *file1;
    file1=fopen("aux.txt","w");
    the file with this name won't be created
    naming a file aux is forbidden in Windows, try creating a folder r text document and naming it aux...
    just some random stuff to spice things up

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

    finally programming in vs code 😍
    and thanks for the video ma'am

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

    Mam how to run the c code in vs code editor cause my code is not running and it shows 'gcc is not recognised '

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

    why are you so cute?

  • @imrannazari8642
    @imrannazari8642 ปีที่แล้ว +7

    #include
    int main(){
    FILE* fptr;
    fptr = fopen("1.txt","w");
    char contant[1000];
    fputs("C is a fun programming language
    ",fptr);
    fputs("And,I love using C language :)",fptr);
    fclose(fptr);
    fptr = fopen("1.txt","r");
    while(fgets(contant, 1000, fptr)){
    printf("%s",contant);
    }
    return 0;
    }

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

      you forgot to close the file again after reopening

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

      @@kfirezer I think some data of file will be loss if he didn`t do that?

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

      @@countrysideshowyaigrock4689 I don't think so, but it is a good practice since maybe you'll use unnecessary resources.

  • @anesp.a913
    @anesp.a913 2 ปีที่แล้ว +7

    Option B is answer

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

    B

  • @bryanbalantes6486
    @bryanbalantes6486 ปีที่แล้ว +6

    /*
    * Create a new file in write mode
    * Write Content
    * C is a fun programming language.
    * And, I love using C language
    * Close the file
    * Again open the file in read mode and read
    the content of the file
    */
    #include
    int main(){
    FILE* fptr;
    fptr = fopen("newText.txt", "w");
    fputs("C is a fun programming language.",fptr);
    fputs("
    And, I love using C language",fptr);
    fclose(fptr);
    fptr = fopen("newText.txt", "r");
    char content[1000];
    if (fptr != NULL){
    while (fgets(content, 1000, fptr)){
    printf("%s", content);
    }
    }else{
    printf("File Open Unsuccessful");
    }
    fclose(fptr);

    return 0;
    }

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

      shouldn't the fclose() be inside if block, at its end. As in case of unsuccessful opening of file (execution of else statement) , fclose() doesn't make any sense.
      Please correct me if I'm wrong

  • @idc-ez7bo
    @idc-ez7bo 7 หลายเดือนก่อน +3

    11:34 Answer : b) FILE* pointer

  • @youssefamgad8199
    @youssefamgad8199 8 หลายเดือนก่อน +2

    Tmrw is my programing final in engineering this just saved my life

  • @amorycomedia3801
    @amorycomedia3801 4 หลายเดือนก่อน +1

    it really helps me improve my knowledge about c programing

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

    hii do you have tutorial on how to setup vscode

  • @SumEarth
    @SumEarth 9 หลายเดือนก่อน +2

    Always a Indian

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

    how to setting when you run code the visual code show the time executing those code? I saw you just click run code and there are time of executing code available there.

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

      Code Runner VSC Extension.

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

    B

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

    B option

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

    Option B : FILE* pointer;
    ---------------------------------------------------------------------------------------------------------------
    #include
    int main() {
    FILE* file;

    file = fopen("newFile.txt", "w");

    fputs("C is a fun programming language
    ", file);
    fputs("And, I love using C language", file);

    fclose(file);

    file = fopen("newFile.txt", "r");

    char content[1000];

    while (fgets(content, 1000, file)); {
    printf("%s", content);
    }
    return 0;
    }

  • @lamaspacos
    @lamaspacos 6 หลายเดือนก่อน +2

    09:50 returns True True 😅

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

    NO : Let me so you
    USE : Let me show you

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

      I actually like the way she says so instead of show lol

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

      @@Titan_Design How about jero instead zero? I like her transcription too

  • @amorycomedia3801
    @amorycomedia3801 4 หลายเดือนก่อน +1

    your content helps me a lot

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

    programming quiz:
    #include
    int main(){
    FILE* fptr;
    fptr = fopen("newfile.txt","w");
    fputs("c is afum programming language
    ",fptr);
    fputs("i love c language",fptr);
    fptr= fopen("newfile.txt","r");
    char content[1000]
    if(fptr!=NULL){
    fgets(content,1000,fptr);
    printf("%s",content);
    }
    else{
    printf("file open is unsuccessfull");
    }
    fclose(fptr);
    return 0;
    }

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

    FILE* pointer

  • @MARK-hw8jm
    @MARK-hw8jm 2 ปีที่แล้ว +3

    Option B

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

    wow, finaly i understood this !thank you a lot for this video👍👍👍👍

  • @PraveenPraveen-us3rp
    @PraveenPraveen-us3rp ปีที่แล้ว +1

    Option B

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

    B. FILE* pointer;

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

    #include
    #include // Include for exit() function
    int main() {
    FILE* fptr;
    char content[1000];
    char userInput[1000];
    // Open the file in write mode
    fptr = fopen("NewFile.txt", "w");
    if (fptr == NULL) {
    printf("Error opening file.
    ");
    exit(1);
    }
    // Prompt the user to enter text
    printf("What do you want to add in NewFile.txt?
    ");
    fgets(userInput, sizeof(userInput), stdin);
    // Write user input to the file
    fputs(userInput, fptr);
    // Close the file
    fclose(fptr);
    // Open the file in read mode
    fptr = fopen("NewFile.txt", "r");
    if (fptr == NULL) {
    printf("Error opening file.
    ");
    exit(1);
    }
    // Read and print the contents of the file
    printf("Contents of NewFile.txt:
    ");
    while (fgets(content, sizeof(content), fptr)) {
    printf("%s", content);
    }
    // Close the file
    fclose(fptr);
    return 0;
    }

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

    She's Nepali

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

    Worst explanation ever .

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

    #include
    int main() {
    // Write C code here
    FILE* fptr;
    fptr=fopen("File.txt","w");
    char content[1000];
    fputs("C is a fun programming language",fptr);
    fputs("And I love C language",fptr);
    fptr=fopen("File.txt","r");
    fgets(content,1000,fptr);
    fclose(fptr);
    return 0;
    }
    It shows the segmentation fault error in the online c programming

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

    Quiz Answer:
    B) FILE* fptr;

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

    Thank you so much for this video. Much needed. 👍🏻

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

    quiz ans. b) FILE *Pointer;

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

    Quiz answer is B

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

    Great videos thank you very much.

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

    Why doesnt this work for visual studio 2019. I feel there is something changed in syntax which needs to be modified . Can you please help me with it.

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

    Answer: B

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

    one complier is showw much better

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

    programiz quiz : the ansewr is B

  • @Option.234
    @Option.234 9 หลายเดือนก่อน

    Without closing the file how it's run

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

    B

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

    B

  • @shubhamsingh-bi7np
    @shubhamsingh-bi7np 2 ปีที่แล้ว +1

    b

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

    B

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

    is there another we condition we can use for that, because that doesnt realy make sense in my head,,, that statement does not return true or false, it just stores the line into the array

    • @pradeep-codes
      @pradeep-codes 6 หลายเดือนก่อน

      The fgets statement doesn't return true or false but it does return a non-Null pointer as it reads a line from the file and stores it in the 'content' array, which is evaluated as true in the loop's condition, causing the loop to continue. Once fgets reaches the end of the file, it returns a NULL pointer, which is evaluated as false in the loop's condition, causing the loop to terminate.

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

    How to use a file when using a real program

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

    B. FILE* pointer;

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

    Your way of teching . easy to undestand

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

    the girl who taught this is pretty

    • @metaMorph21
      @metaMorph21 ปีที่แล้ว +4

      She is cute ,isn't she?

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

      So...pretty

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

      Simp ranmati

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

      @@Baka100simp for thinking a girl is pretty? no wonder yall are third world countries

    • @antoine2571
      @antoine2571 4 หลายเดือนก่อน +6

      Programmers seeing a girl for the first time in months because they fell into programming spiral :

  • @PankajSingh-ww5pl
    @PankajSingh-ww5pl ปีที่แล้ว +1

    Mine was 1000th like to the vid....😎😎
    apart really helpful

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

    Option B

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

    FILE *pointer

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

    quiz answer option B

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

    option b

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

    b

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

    thank you soooo much madam

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

    These. Video is really very helpful

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

    Thank you!

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

    A

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

    B

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

    What do i need to do if it thinks that the file doesnt have any text?

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

      I dont know ur code so

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

    How can we open a file in a "for loop and create different files for each size of arrays.
    For example:
    For ()
    {
    file 1 for array[0]
    File 2 for array[1].…..
    }

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

    Answer:b

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

    5:52

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

    Mam from where I can check this?

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

    amazing teacher

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

    nice

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

    Nice teaching

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

    To declare file pointer we use FILE.pointer

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

      no..?

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

    // Online C compiler to run C program online
    #include
    int main() {
    FILE* fptr;
    fptr = fopen("one piece.txt","r");
    char content[1000];
    fputs("i love one piece anime
    ",fptr);
    fputs("the most one that i love in one piece is lufy", fptr);
    fclose(fptr);
    fptr = fopen("one piece.txt","r");
    while(fgets(content, 1000, fptr)){
    printf("%s",content);
    }
    return 0;
    }

  • @JeongWoonKim-i4j
    @JeongWoonKim-i4j ปีที่แล้ว

    #include
    int main() {
    FILE* fptr;
    fptr = fopen("newFile.txt", "w");
    fputs("C is fun programming language
    ", fptr);
    fputs("And, I love using C programming", fptr);
    fclose(fptr);
    fptr = fopen("newFile.txt", "r");
    char content[1000];
    if (fptr != NULL) {
    while(fgets(content, 1000, fptr)) {
    printf("%s", fptr);
    }
    }
    else {
    printf("File open Unsuccessful");
    }
    fclose(fptr);
    return 0;
    }

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

    #include
    int main() {
    FILE* fptr;
    fptr = fopen("newFile.txt", "w");
    fputs("C is a fun programming language
    ", fptr);
    fputs("And, I love using C language", fptr);
    fclose(fptr);
    char content[1000];
    fptr = fopen("newFile.txt", "r");
    if (fptr != NULL) {
    while (fgets(content, 1000, fptr)) {
    printf("%s", content);
    }
    }
    else {
    printf("File Open Unsuccessful");
    }
    fclose(fptr);
    return 0;
    }