Files
-
hi, I need to open an text file to save the output data from the machine, i could open the text file and could write the output data to the text file, but the problem is how could i save the previous test data output if i again run the program? file = fopen("output.txt", "w+"); ... fputs(txt, file); fputs("\n", file); If i run the program, i could write the data of the present running data output, i need to save the old output data for the checking the drift? Can i use rewind???? Thnaks in advance
-
hi, I need to open an text file to save the output data from the machine, i could open the text file and could write the output data to the text file, but the problem is how could i save the previous test data output if i again run the program? file = fopen("output.txt", "w+"); ... fputs(txt, file); fputs("\n", file); If i run the program, i could write the data of the present running data output, i need to save the old output data for the checking the drift? Can i use rewind???? Thnaks in advance
use file = fopen("output.txt", "a+"); to append, see function description in MSDN. Regards Ray "Je Suis Mort De Rire" Blogging @ Keratoconus Watch
-
hi, I need to open an text file to save the output data from the machine, i could open the text file and could write the output data to the text file, but the problem is how could i save the previous test data output if i again run the program? file = fopen("output.txt", "w+"); ... fputs(txt, file); fputs("\n", file); If i run the program, i could write the data of the present running data output, i need to save the old output data for the checking the drift? Can i use rewind???? Thnaks in advance
-
Open the file for append, "a(+)" instead of "w+". "w+" always creates the file. "a" creates the file if it doesn't exist. Else, it adds to at the (previous) end of the file.
ya thankyou, it is working!! Its appending from the end of the previous data file, like 1 // 1 2 3 4 .......one data output 2 3 4 5 //5 6 7 8.....another data output 6 7 8 if i would like to have as, 1 2 3 4 //as first data output nad the next file output should begin in new line as 1 5 2 6 3 7 4 8.. hwo could i proceed??i would like tos tart in new line again
-
ya thankyou, it is working!! Its appending from the end of the previous data file, like 1 // 1 2 3 4 .......one data output 2 3 4 5 //5 6 7 8.....another data output 6 7 8 if i would like to have as, 1 2 3 4 //as first data output nad the next file output should begin in new line as 1 5 2 6 3 7 4 8.. hwo could i proceed??i would like tos tart in new line again
You mean a new column. Well, that's not easy to do. Considder the data in the file (from the first run). It's something like this: 1 2 3 4 Now you want to insert characters (" 5") in the first line, after "1" and before the character. To be able to do that (in the simplest way), you will have to create a new file. Then read from the old file, one line at the time, modify that line and then write the modified line to the new file. When the new file is done, delete the old file and rename the new file to the old files name. Not very easy for a beginner. Can you considder another principle?
-
You mean a new column. Well, that's not easy to do. Considder the data in the file (from the first run). It's something like this: 1 2 3 4 Now you want to insert characters (" 5") in the first line, after "1" and before the character. To be able to do that (in the simplest way), you will have to create a new file. Then read from the old file, one line at the time, modify that line and then write the modified line to the new file. When the new file is done, delete the old file and rename the new file to the old files name. Not very easy for a beginner. Can you considder another principle?
Helo Mr. Kakan, Is it possible to do so 1 2 3 4 5 6 7 8 writing the new data in another next line???
-
Helo Mr. Kakan, Is it possible to do so 1 2 3 4 5 6 7 8 writing the new data in another next line???
Hello chaitanya. That's much easier. That way, you just append to the file. Just make sure you put a '\n' character ONLY at the end of line. Today, you write a '\n' for each value, which gives a newline after each value. That's the reason why you get each value on a separate text line in the file. I don't know what function you are using for writing to the file today, but i suspect you are using fputc() or fputs(), right? There are numerous ways to write to a file, this is just one way. You can to this, using fputc. (I assume FILE * file): int number = '1'; fputc(number, file); fputc((int) ' ', file); number = '2'; fputc(number, file); fputc((int) ' ', file); number = '3'; fputc(number, file); fputc((int) ' ', file); And the last number: fputc(number, file); fputc((int) '\n', file); Or, if you got all numbers at the same time, you can do this: fprintf(file, "%d %d %d %d\n", 1,2,3,4); fprintf(file, "%d %d %d %d\n", 5,6,7,8); This is very basic knowledge, I think you should read a good beginners book about C and then go on with a book about C++. Good luck Kakan