C and C++ Programming Resources | C & C++ Code Example Index | C++ Code Example Index





The C File Input/output and C Processor Directives Sample Codes Index Page


The following links provide C program example on how to use the C file input/output for opening, reading, writing, closing and processing the files. The second part demonstrates the program examples on how to use the C preprocessor directives.


C File Input/Output (The C file input/output program samples - printf(), scanf(), scanf_s() etc.)

  1. Opening, reading, writing and closing a text file, block by block using fopen()/fopen_s(), fread() and fwrite() C functions

  2. Opening and reading file content randomly and display it using fopen()/fopen_s(), fseek(), ftell() and fgets() C functions

  3. Reading, writing, rewind the file pointer of the binary data file using fopen_s()/fopen(), fread(), fwrite() and rewind() C functions

  4. How to use fopen() and fscanf()/fscanf_s() function to read from a file, process and write the result to another file

  5. Redirecting the standard output to a text file C program example

  6. Deleting a file using the remove() C function

  7. Using rename() C function to change a file name

  8. Copying a file C program example using the C file input/output functions

  9. Opening file, reading and writing one line at a time using fputs()/fputws(), fopen()/fopen_s() and fgets()/fgetws() C functions

  10. Reading and writing one character at a time using fopen()/fopen_s(), fgetc()/fgetwc() and putchar()/putwchar() C functions

  11. Finding, opening and closing a text file for reading using C file input/output functions



    C Preprocessor Directives (The C preprocessor directives code examples)

    1. Testing some string properties using C assert() function

    2. The # and ## C/C++ preprocessor directives program example

    3. The #if, #ifdef, #elif...defined, #undef, #endif, #define, #if...defined preprocessor directives C++ program example

    4. How to use the #pragma message preprocessor directive

    5. Using the #if...#endif and #pragma message for conditional compilation

    6. The #error message usage for displaying the error message for the stated condition

    7. Another #error preprocessor directive C code example




C and C++ Programming Resources | C & C++ Code Example Index | C++ Code Example Index