Home > Back-end >  Editing files using C
Editing files using C

Time:06-16

Input.txt:

File entry structures:
[0] ""  0       -1
[1] ""  0       -1
[2] ""  0       -1
[3] ""  0       -1
[4] ""  0       -1

I want to create a new file (output.txt). The C program replaces the first occurrence of "" with "Testfile", so it looks like:

Output.txt:

File entry structures:
[0] "Testfile"  0       -1
[1] ""  0       -1
[2] ""  0       -1
[3] ""  0       -1
[4] ""  0       -1

My work so far:

#include <stdio.h>

int main() {
    FILE *input_file, *output_file;
    int  size, fblock;
    char index[81];
    char name[81];
    
    
    input_file = fopen("input.txt", "r");
    
    output_file = fopen("output.txt", "w");
    
    // ignore "File entry structures:" line when reading/writing
    
    while (fscanf(input_file, "           
  • Related