Question: I have a **datas.txt** file :

format : name surname debt payment

```
bir bir 100 2 
iki iki 200 2 
eray alakese 100 5 
john doe 2000 10 

```

I'm learning C and **i know just simple file functions (fscanf, fprinf, fopen etc.)**

I'll

1. ask user name and surname with `scanf`and then assign them to *name* and *surname* variables.
2. It will search file for *name* and *surname* and then assign debt and payment to *debt*, *payment* variables ( `fscanf(file, "%s %s %d %d", name, surname, &debt, &payment);`)
3. Delete or modify this line

This is my source code .

```
    scanf("%s", &name);
    scanf("%s", &surname);
    file = fopen("datas.txt", "r");
    /* this fscanf() is working as expected. There is no problem. */
    fscanf(file, "%s %s %d %d", name, surname, &debt, &payment);

    /* modify and delete actions here */
    fclose(file);

```

Examples :

1. I want to delete record of "John Doe" .
2. I want to decrease "John Doe"'s debt to 100$

Answer: 
You cannot delete/modify[\*] individual lines of a text file; the only solution is to 1) create a new temporary file, 2) copy the contents up to, but not including, the line that you want modified/deleted, 3) output the modified line, 4) copy the rest of the original file, 5) replace the old file with the temporary file.

[\*] Modification is possible ONLY if the modified line has the same length as the original line.

EDIT: PS: Using fgets, followed by sscanf (or some other way of tokenizing the line) will save you much grief.
In order to delete or alter a line, you have to "shift" everything after it. For example, consider these two files:

```
bir bir 100 2           bytes 0-14
iki iki 200 2           bytes 15-29
eray alakese 100 5      bytes 30-49
john doe 2000 10        bytes 50-67

```

and

```
bir bir 100 2           bytes 0-14
iki iki 200 2           bytes 15-29
john doe 2000 10        bytes 30-57  <-- byte offsets have changed

```

This is certainly possible to do, but it's pretty complicated to support in general (you'd have to do a lot of seeks and tells). The more usual approach is to effectively copy the file: you read in from your input-file and print everything out to an output-file, making the modifications you need. (For example, to "delete" a line, you simply don't print that line.) Then, at the end, after closing both files, you "rename" the output-file to overwrite the input-file. This is the approach that command-line utilities such as `sed` and `perl` use when instructed to modify a file "in-place".