need help with code

How do i set to edit existing client not making new one ???? please help ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 void edit_Balance()
{
     int accNum, num;	
     char Sur[15];	
     char Name[10];
     string izv;
     float balance, sm, newbalance;
     ifstream fails ("DatuBaze.txt");
     if (!fails.eof())
     {
     fails >> accNum >> Name >> Sur >> balance;
     }
     cout << "Enter client Nr.:\n";
     cin >> num;
     if (accNum == num)
     {
     cout << accNum <<" - "<< Name <<" "<< Sur <<" : "<< balance << " EUR" <<endl;
     cout << "Is it right client [y][n]:\n";
     cin >> izv;
          if (izv == "y")
          {
                  cout << "enter cont balance\n";
                  cin >> sm;
                  balance = balance + sm;
          }
          
      fails.close();             
     }
     ofstream fails2("DatuBaze.txt", ios::app);
     fails2 << accNum <<' '<< Name <<' '<< Sur <<' '<< balance << endl;
     fails2.close();
     system("pause");
     main();    
     
     
}
anyone?
Your question kinda makes no sense. Re-phrase it and add detail please.
 
   main();   


Also you cant call main.
I believe you want to look into passing parameters into functions (by reference).
I'ts not full code just part with what i have problem... when ever i try to edit existing entry it makes new one and also keeps the old one but i need it to change existing!
Can you also post your main function and the exact error you are getting? What should your program do? What does it do that it shouldn't be doing? Because now we have to guess at what the error is exactly. Judging from the code you posted, I guess you intended to create a "replace in file" mechanism? You seem to be appending at the end of the file in the example you provided, C++ doesn't magically search for the name you want in the file and replaces it with new values, you have to write this yourself. You could take a look at the tellg and seekp functions of ifstream and ofstream. Although in your case, it might be better to use a regular fstream since you seem to be reading and writing to the same file.

Also, as @TarikNeaj also posted, you shouldn't call main. Although it actually is allowed to do so (main is just a function like all others).
Topic archived. No new replies allowed.