#29: C File Handling | C Programming for Beginners

Поділитися
Вставка
  • Опубліковано 6 жов 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

  • @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");

  • @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

  • @youssefamgad8199
    @youssefamgad8199 8 місяців тому +2

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

  • @higgsboson6274
    @higgsboson6274 2 роки тому +14

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

  • @amorycomedia3801
    @amorycomedia3801 4 місяці тому +1

    it really helps me improve my knowledge about c programing

  • @shivamchakraborty9573
    @shivamchakraborty9573 4 дні тому

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

  • @amorycomedia3801
    @amorycomedia3801 4 місяці тому +1

    your content helps me a lot

  • @anesp.a913
    @anesp.a913 2 роки тому +7

    Option B is answer

  • @mohammadabdullahaalforhad1375
    @mohammadabdullahaalforhad1375 8 місяців тому

    Your way of teching . easy to undestand

  • @danutab3306
    @danutab3306 Рік тому +2

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

  • @lamaspacos
    @lamaspacos 6 місяців тому +2

    09:50 returns True True 😅

  • @devmalya2004
    @devmalya2004 2 роки тому +2

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

  • @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 '

  • @MARK-hw8jm
    @MARK-hw8jm 2 роки тому +3

    Option B

  • @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.

  • @jypee8070
    @jypee8070 Рік тому +3

    hii do you have tutorial on how to setup vscode

  • @Jeremyak
    @Jeremyak 5 місяців тому

    Great videos thank you very much.

  • @paypali2238
    @paypali2238 2 роки тому +4

    B option

  • @ironmonkey1990
    @ironmonkey1990 5 місяців тому

    Thank you!

  • @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.

  • @JocularmarsAH
    @JocularmarsAH 10 місяців тому

    thank you soooo much madam

  • @One_piece1089
    @One_piece1089 Рік тому

    amazing teacher

  • @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].…..
    }

  • @PankajSingh-ww5pl
    @PankajSingh-ww5pl Рік тому +1

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

  • @Apekshakene
    @Apekshakene Рік тому

    These. Video is really very helpful

  • @narsimhanarsimha5244
    @narsimhanarsimha5244 Рік тому +1

    To declare file pointer we use FILE.pointer

  • @nilamvohra9340
    @nilamvohra9340 Рік тому

    Nice teaching

  • @racingfan372
    @racingfan372 Рік тому +1

    Quiz answer is B

  • @dinbandhujana1390
    @dinbandhujana1390 2 роки тому +2

    FILE* pointer

  • @b_01_aditidonode43
    @b_01_aditidonode43 Рік тому

    quiz answer option B

  • @mohammadabdullahaalforhad1375
    @mohammadabdullahaalforhad1375 8 місяців тому

    quiz ans. b) FILE *Pointer;

  • @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 8 місяців тому +3

    11:34 Answer : b) FILE* pointer

  • @Option.234
    @Option.234 9 місяців тому

    Without closing the file how it's run

  • @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.

  • @gowthamg1204
    @gowthamg1204 Рік тому +2

    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.

  • @HIMANSHUJSBH52QPSF
    @HIMANSHUJSBH52QPSF 4 місяці тому

    Answer: B

  • @yadlaaravind811
    @yadlaaravind811 Рік тому

    Answer:b

  • @shubhamkumargupta7953
    @shubhamkumargupta7953 6 місяців тому

    option b

  • @peterrepaso1293
    @peterrepaso1293 Рік тому

    How to use a file when using a real program

  • @mahisflow1165
    @mahisflow1165 2 роки тому

    Mam from where I can check this?

  • @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

  • @alaaanees9955
    @alaaanees9955 Рік тому

    nice

  • @One_piece1089
    @One_piece1089 Рік тому

    programiz quiz : the ansewr is B

  • @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;
    }

  • @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

  • @JeanNepoMunezero
    @JeanNepoMunezero Місяць тому

    B. FILE* pointer;

  • @khushbhatt5378
    @khushbhatt5378 9 місяців тому

    one complier is showw much better

  • @LogXTX
    @LogXTX Рік тому +1

    She's Nepali

  • @SumEarth
    @SumEarth 9 місяців тому +2

    Always a Indian

  • @Vyom330
    @Vyom330 8 місяців тому

    5:52

  • @LostInTheMysteriousWorld
    @LostInTheMysteriousWorld 3 місяці тому

    Quiz Answer:
    B) FILE* fptr;

  • @shubhamsingh-bi7np
    @shubhamsingh-bi7np 2 роки тому +1

    b

  • @janewaguthi4342
    @janewaguthi4342 Рік тому

    A

  • @azhanisyahputra9867
    @azhanisyahputra9867 Рік тому +35

    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 :

  • @ayushkumarswain7334
    @ayushkumarswain7334 Рік тому +3

    why are you so cute?

  • @Aksar_Ojha
    @Aksar_Ojha 6 місяців тому

    Worst explanation ever .

  • @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;
    }

  • @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

  • @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;
    }

  • @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;
    }

  • @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;
    }

  • @PraveenPraveen-us3rp
    @PraveenPraveen-us3rp Рік тому +1

    Option B

  • @kirwanaericroberts4803
    @kirwanaericroberts4803 Рік тому +2

    B

  • @ardent307
    @ardent307 Рік тому

    FILE *pointer

  • @bryanbalantes6486
    @bryanbalantes6486 Рік тому

    B. FILE* pointer;

  • @suhailpasha698
    @suhailpasha698 Рік тому

    b

  • @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;
    }

  • @umehabiba5472
    @umehabiba5472 2 роки тому +1

    Option B

  • @wasswapeter3790
    @wasswapeter3790 2 роки тому +1

    B

  • @fateemahamosuro4788
    @fateemahamosuro4788 8 місяців тому

    B

  • @rakesh1045
    @rakesh1045 Рік тому

    B

  • @adarsh70076
    @adarsh70076 Рік тому

    B