text - How to write to a textfile in c (with the intended functionality) -


I am trying to know the syntax for writing data (characters, integers and strings). I have studied the content of the following link and have written the following code. The purpose of the code is to collect the data in the text file as follows:

33
Hello

15
OK

If I have the following inputs 33, hello, 15, ok and 0 make But after running the program, when I open it, the text file is completely empty. Is there someone who is skilled in storing data in a text document, which is doing me wrong, can give me some hint? Or if there is any other good tutorial you know?

My test code is attached below [I can compile and run it without any problem, except that it does not do things which I hope: ()

 Text string named name string_ring_input (char msg []) {fp = fopen}  stdin_buff [20]; int stdin_int; FILE * fp; char * filename = "data.txt"; // (Filename, "w"); // opens the text file in write mode if (fp == NULL) {printf ("Unable to open file! \ N");} fseek (fp, 1, SEEK_END); // Text file fputs (msg, fp); // text file putc (' \ N ', fp); // new document text document putc (' \ n ', fp); // writes new message; closes fclose (fp); // in text document; closes text file} Zero Hendel_InterGerin Input (int NBR) {FP = FOPN (filename, "W"); // Opens text file in write mode if (fp == NULL) {printf ("Unable to open file! \ N"); } Fseek (fp, 1, SEEK_END); // The text file fputc (nbr, fp); // writes the NBR in the text while writing the file putc ('\ n', fp); // text document in fclose (fp) new line; // closes text file} zero main () {while (1) {menset (staden_buff, '\ 0', 10); // stdin_buff cleans the contents of printf ("Enter integer (Enter 0 to exit):"); fgets (stdin_buff, 9th, stdin); // gets an input from the keyboard (user is expected to use 0-9 numbers only) stdin_int = atoi (stdin_buff); Handle_Integer_input (stdin_int); If (stdin_int == 0) {break; } Memset (staden_buff, '\ 0', 10); // stdin_buff cleans the contents of printf ("Enter the string (insert 0 to exit):"); fgets (stdin_buff, 9th, stdin); Retrieves input from // keyboard handle_String_input (stdin_buff); If (stdin_buff [0] == '0') {break; }}}   

What did I remember / did not understand? Any suggestions about improvements are appreciated! In the FOPAN statement, instead of "A", use "A" (for append).

"W"

Currently, if you end your interactive session by entering the integer '0', then the file will appear blank. If you end up with the string '0' then you should only see 0 characters.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -