I have got three numbers in a text file text file format <serial number>one white space<time stamp>one white space<income in dollar> -----Inside text file (not including this line)------- 1 2:00 4.4 2 3:00 5.6 3 4:00 5.8 4 5:00 5.6 5 6:00 4.3 ------End of text file (not including this line)----- I need to read those lines with c line by line. I need to break first line in three parts and put serial number in integer, time in string or time format. And dollar in floating point. And now convert that dollar to Japaneses Yen then write in another output text file.
Check this code #include<stdio.h> #include<conio.h> void clearArray(char time[], int len); void main(){ FILE *fp, *fp1; float price, new_price, rate; clrscr(); /*Edit this to set the conversion rate*/ rate = 117; /*Edit this to point to the original file*/ fp = fopen("s.txt", "r"); /*Edit this to point to the new file*/ fp1 = fopen("yen.txt", "w"); printf("-----------------------------------------------\n"); printf("|S. No.| Time | Old Price($) | New Price(Y) |\n"); printf("-----------------------------------------------\n"); while(!feof(fp)){ fscanf(fp, "%d %s %f", &sl, time, &price); new_price = rate * price; fprintf(fp1, "%d %s %f\n", sl, time, new_price); printf("|%5d |%7s |%13f |%13f |\n", sl, time, price, new_price); } printf("-----------------------------------------------\n"); getch(); } Code (markup): You can remove the 5 printf statements and the getch statement, if you are not interested in the tabular output.