ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
%.3f
instead of a float number.
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.
/* For each input sample, print the sample, followed by the output */
for( i=0; i<p->num_inputs; i++)
{ for( j=0; j<p->io_nodes[0]; j++)
fprintf(out, "%lf ", p->inputs[i].input[j]);
fprintf(out, " ");
for( j=0; j<p->io_nodes[1]; j++)
fprintf(out, "%l0.3f ", p->inputs[i].output[j]);
fprintf(out, "\n");
}
}
This is the writeoutputdata() that program uses. I also tried as you can see l0.3f but it didnt work
To be honest I am not really familiar with formats in C so any help will be really precious.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.