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: 
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".
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