ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Writing to text files in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ส.ค. 2024
  • Check out our Discord server: / discord

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

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

    You have one of best C programming tutorials on youtube. Your channel is a precious gem. Thank you for all your hard work.

  • @tapiocaferoz02
    @tapiocaferoz02 3 ปีที่แล้ว

    Clear and objective explanation... I'm in love with yours videos, sir

  • @alexandru-cristiansandu1016
    @alexandru-cristiansandu1016 2 ปีที่แล้ว

    Nice informative video, keep up the good work!

  • @Anndrew154
    @Anndrew154 4 ปีที่แล้ว

    thanks for the video man!

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

    hi , just a quick note that when you clarify the struct type again at the end the clarification at the beginning is optional,
    so you can write it like:
    typedef struct{
    }point;

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

    You can use,
    # pragma warning(disable:4996)
    at the start of your file it disables warnings related to _s or secure functions in Newer versions of Visual Studio.

    • @CodeVault
      @CodeVault  3 ปีที่แล้ว

      Nice! Thanks for the tip. Nowadays I use the macro _CRT_SECURE_NO_WARNINGS to remove those pesky warnings. Very strange for them to actually be in the standard while only MSVC implementing them :/

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

    You are very impressive with your videos..

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

    thank you so much, really

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

    Where can I learn more about why FILE is used, or the difference between any of these functions and their differences between them and their _s counterparts, or why a buffer is needed.

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

      FILE is just the type that is used for file handles in the C standard library. I will make a video explaining the _s functions in more detail

  • @SaltWaterLazarus
    @SaltWaterLazarus 3 ปีที่แล้ว

    Question, should you write strlen(buffer_out) + 1 to include \0 in general or does it not matter?

    • @CodeVault
      @CodeVault  3 ปีที่แล้ว

      No. The \0 (aka the NULL terminator) is a C-specific standard for strings and some editors wouldn't know how to handle that NULL terminator.

    • @SaltWaterLazarus
      @SaltWaterLazarus 3 ปีที่แล้ว

      @@CodeVault I see, thank you

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

    hi, im new to reading and writing files, may i know why you declared two char strings buffer_in and buffer_out and only used buffer_out ?

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

      I use the buffer in the next video regarding reading from files

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

    Hi. fopen and sprintf have different parameters now (2 in fopen and 2 + n for sprintf). Did that change over the course or am I missing something?

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

      If you are using the _s versions, they take more parameters

  • @karique01
    @karique01 3 ปีที่แล้ว

    Thank's for these videos, how can i set the txt file in utf8 for characters like "ñ"

    • @CodeVault
      @CodeVault  3 ปีที่แล้ว

      I haven't worked with those characters in C but, I think, a good starting point is to take a look at the wchar functions that C has to offer: en.wikibooks.org/wiki/C_Programming/wchar.h
      www.cplusplus.com/reference/cwchar/

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

    I get a warning "passing argument # of 'sprintf' makes pointer from integer without a cast".

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

      Oh! If you're using sprintf (without the _s) then you don't need to pass the 256 integer as the second argument

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

    Is there a way to get ready/write capabilities on the same file at the same time? Is that best practice?

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

      Yes, you can call fopen with the r+ tag for both reading and writing to the file. Just be careful where the file cursor is. Here's more documentation: cplusplus.com/reference/cstdio/fopen/

  • @puzzlelovers529
    @puzzlelovers529 4 ปีที่แล้ว

    fprintf is also a convenient function to use, right?

    • @CodeVault
      @CodeVault  4 ปีที่แล้ว

      Yep, fprintf can also be used

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

    Sal,tu esti din romania?

  • @lamhonghai123
    @lamhonghai123 3 ปีที่แล้ว

    what is difference between fpritnf and sprintf ?

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

      fprintf takes in a stream as its first parameter (so either a file or stdout/stderr), so it writes to those
      sprintf takes in a pointer to char as its first parameter and writes the data to that string

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

    Are u portugues?

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

      No, I'm Romanian

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

    this work with me
    i don't have fopen_s
    #include
    #include
    typedef struct Point {
    int x, y;
    } Point;
    int main(int argc, char* argv[]){
    Point p1 = {
    .x = 12,
    .y = -9
    };
    FILE* in;
    FILE* out;
    char buffer_in[256], buffer_out[256];
    out = fopen("point.dat" , "w");
    sprintf(buffer_out, " %d , %d
    " , p1.x , p1.y);
    fwrite(buffer_out, sizeof(char), strlen(buffer_out), out);
    return 0;
    }

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

      That's okay. fopen_s (or any _s functions) are available only if you're using the VisualC compiler on Windows