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.
The way I usually handle something like this is to write a function that can "read in" your data and store it to some structure. Then a function to write data from the structure to a file.

This way you can just manipulate the data in an array. This also makes your program more extensible to doing things like sorting, or extra math that you couldnt have done by just writing over the top of the file.

e.g. try writing a function that can read in to a struct like:

```
struct Client
{
    char name[255];
    double owes;
    double paid;
}

```

What you then do make an array of these structures and manipulate those.
You'll learn a lot about structs, dynamic memory allocation, and you'll no doubt run in to some interesting issues that will help you learn.

My advice is to also skip C and go for C++... learning this stuff using iostreams instead of the \*printf/\*scanf functions and vectors is probably going to be better for you in the long run