| DannyPt (12) | |||
|
i am doing a program where i have to create a file, witch i have to ask where to save, the name, and the extension, and then it have to be writing wat i want for the all program, but at the end i have a question about want to leave the program or not, if this anwer is to get out of the program i want him to get out of the program and save the file, but if the answer is to continue in the program i want him to continue writing withou deleting anything... i looked in this website: http://www.mattjustice.com/cnotes/c_fileio.html but the program allways delete the contents of the file this is the part thtat creates the file in my program:
this file is allways created in the beggining of the program... if anyone can help me, i would be thankfull | |||
|
|
|||
| JLBorges (1756) | |||
Is this what you intended?
| |||
|
|
|||
| DannyPt (12) | |
| what will that do? is to only writte in the file and to not delete wat is in it? | |
|
|
|
| JLBorges (1756) | |||
|
Line one tries to open an existing file for reading and writing. If that does not work ( f is null ) line two tries to create a new file. Ckeck out std::FILE* f = std::fopen( "c:\\euromilhoes.txt", "a+" ) ;http://www.cplusplus.com/reference/clibrary/cstdio/fopen/ That may be just what you need. Note: In the original code,
| |||
|
|
|||
| DannyPt (12) | |
|
i allready saw wat was wrong... in the website that i got it didnt meantion the "a+" and that is the solution... tks. now how can i ask to the user to tell where to create the file and how to call it? because i cant put something like: f=fopen("%c:\\euromilhoes.txt", driver,"a+");
| |
|
|
|
| JLBorges (1756) | |
|
> now how can i ask to the user to tell where to create the file and how to call it? I'm not sure I understand that question. | |
|
|
|
| DannyPt (12) | ||
|
will i am running the program, the program should ask the user in whwat driver and what the name of the file to be created. something like this:
now i saw one problem... the file euromilhoes.txt that i did in f=fopen("%c:\\euromilhoes.txt", driver,"a+");now i cant delete it... do you know why? | ||
|
Last edited on
|
||
| megazord32 (1) | ||
|
well, i'm with the same doubt. The program should ask:
How do I do that? | ||
|
Last edited on
|
||
| JLBorges (1756) | |||
Use a std::string to hold this information. http://www.cprogramming.com/tutorial/string.html
| |||
|
|
|||
| DannyPt (12) | |
|
isnt there another way to do it? because i dont understand nothing about strings and i when i insert your program into mine it just give me errors and i really dont understand all of that cout and cins... never used that, and in my all program i am using printf and scanf, is it possible to substitute? | |
|
Last edited on
|
|
| JLBorges (1756) | |
|
> i dont understand nothing about strings ... > and i really dont understand all of that cout and cins ... It is perfectly fine that you do not understand something at this moment; folks here would be very willing to help you understand. But you have to make an effort to try and understand C++. If you are unwilling to do that, perhaps you should post your questions on a C board. I've been told that this is a fairly good one: http://cboard.cprogramming.com/c-programming/ | |
|
Last edited on
|
|
| DannyPt (12) | |
| but isnt in C that it work with the cout and cin insted of the printf and scanf? | |
|
|
|
| Moschops (5981) | |
| No. C++ works with cout and cin. C does not. | |
|
|
|