![]() |
| ||
| Output in Text file-How to apply fprintf()? Greeting to all, I have been trying to apply "fprintf()","fopen()" and "fclose()" into the following source code but still fail to get the right way. As I do not have any C program book to refer to, I really appreciate it if someone could show me how should I go about it. As I have mentioned in my previous thread, I am trying to transfer the output (refer to the source code below) to a text file such as showing the output in the notepad file. #include <stdio.h> #include <math.h> main() { double p,min,max,temp; double pymt[3][100],total[3][100]; int a=0; int n; printf ("Enter loan amt(p): "); scanf ("%lf",&p); printf ("\nKey in minimun interest rate(i): "); scanf ("%lf",&min); printf ("\nKey in maximun interest rate(i): "); scanf ("%lf",&max); printf("%s\t%s\t%s\t%s\n","Monthly payment","Total payment","Interest rate in %","Year"); for(n=20;n<=30;n+=5){ int b=0; temp=min; for(;temp<=max;temp+=0.25){ pymt[a][b]=((temp/100)*p)/(1-(pow((1+(temp/100)),-n))); total[a][b] = pymt[a][b]*12*n; printf("%.2f\t\t%.2f\t\t%.2f\t\t\t%d\n",pymt[a][b],total[a][b],temp,n); b++; } a++; } return 0; } |
| ||
| Re: Output in Text file-How to apply fprintf()? You might try something like this. #include <stdio.h>Some reference to the functions would be helpful. |
| ||
| Re: Output in Text file-How to apply fprintf()? Hey go to the tutorials fourm and check out the tut for file i/o using fstream.(C++) Here's the link: http://www.daniweb.com/techtalkforums/thread6542.html |
| ||
| Re: Output in Text file-How to apply fprintf()? Quote:
but i notice that the data of the file is being replace by the new data each time the program is running. how can it be program so that the new data is continue at the bottom not replace the old data. thanz |
| ||
| Re: Output in Text file-How to apply fprintf()? Maybe open the file for append mode (open or create text file for writing at end-of-file). FILE *file = fopen("file.txt", "a"); |
| ||
| Re: Output in Text file-How to apply fprintf()? Hi Dave Sinkula, how can we check wheather the user key in is numerical or alphabetical?? can we change the alphabatical to numerical?? and if i want the user to put the name of the file can i put like this... char n; printf("\nPut the file name\n"); scanf("%s",&n); FILE *file = fopen("c:\\"n".txt", "a"); thanks for help |
| ||
| Re: Output in Text file-How to apply fprintf()? Quote:
Quote:
|
| All times are GMT -4. The time now is 5:10 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC