problem with C (printing out to text file)
Hey there
I recently compiled successfully a C program and the fact is that the program seems to work correctly. The program deals a lot with passing parameters from a text file, processing the data, outputing to the screen some information and finally prints out to a text file the output. The fact is that everything seems to work well but when outputting to the text file i get as an output Quote:
There should be nothing wrong with the code of the program because i know people who they have used it without troubles. Help from someone familiar would be grateful. Thanks for your time |
I guess that's the format string you use to output the data? Try %0.3f etc.
|
Yeah, it sounds like your format specifier string isn't correct. You need to post the line(s) of code that write to the file to be sure though.
|
Quote:
To be honest I am not really familiar with formats in C so any help will be really precious. Thanks for your time. |
Code:
void writeoutputdata(p, out) it should be "%0.3lf" are u sure that u donot want any thing to be printed before decimal, if not give some number before '.' like "%5.3lf" |
Dear varun_shrivastava
Thanks very much for your reply. I believe that you could help me. To be honest I am not really familiar with text formats in C. The fact is that the program outputs with big decimals like 0.321343239 and it is a constraint for me as soon as lets say that i want to use some large piece of data. In such cases i get a segmentation fault message. I would really like from you if you could tell me a way that i could print out double numbers with not large floating points. According to the previous given number something suitable for me should be 0.32 Thanks really much for your time |
Quote:
i m unable to understand what u want to say in the above line quoted |
you won't ever get a seg fault because your float has too many significant digits to printf.
you should post the problem, not how you think it should be done. |
I am really sorry but I just tried to describe my case.
Probably you are right but i am not really expert with C and because i tried many times to make that program work but without any success i thought that someone could help me. Any ideas now how can i print out a number like 0.321343239 with less signficant bits, like as i said 0.32? If someone knows Java and C i would have been really obliged to him if he could show me a way to do it Thanks again for your time and for sharing your knowledge. |
try %.3Lf,
I think float should be formatted with "L" instead of 'l'. |
if u write "%10.5f" it means
total of 10 characters will be printed with 5 decimal digits and they will be right justified whereas "%-10.5f" will print the same but left justified so u want to print your output as 0.32 so there are 4 characters and two after decimal : use "%4.2lf" read c programming language by Denice Ritche : Best book to learn c programming |
All times are GMT -5. The time now is 12:45 PM. |