#include int main() { FILE *fp,*fp2; /*two file pointers declared*/ double val; /*A double type variable declared, this is used to store the values read in*/ int val_int; /*An Int type variable is declared, this is used to store the integer version of the double*/ char ch; /*A char variable is declared, this is used to test for linefeeds or end of file EOF*/ if((fp2=fopen("newfile.txt", "w"))==NULL){ /*if statement declaration. The file pointer is set to point to the file in write mode.*/ printf("Error Creating file"); /*This file won't exist and so is created. */ exit(1); /*The If statement checks it worked, if it didn't the pointer will return NULL */ } /*If the test failed, an error message is printed. */ if((fp=fopen("myfile.txt", "r"))==NULL){ /*if statement declaration. The file pointer is set to point to the file in read mode.*/ printf("Error opening file"); /*The If statement checks it worked, if it didn't the pointer will return NULL */ exit(1); /*If the test failed, an error message is printed. */ } do{ /*Start of a do... while loop*/ fscanf(fp,"%lf",&val); /*Scans in the first value, it stores it in the variable val, of type double*/ ch= getc(fp); /*Scans for a single character, this will be our space between the values. Or it will be a linefeed, or EOF*/ val_int = val; /*Casts the double to type int, and stores it in the variable val_int*/ printf("%lf ",val); /*prints the double value on screen*/ fprintf(fp2,"%d ",val_int); /*prints the int value into the created file*/ if(ch == '\n' || ch ==EOF){ /*if the character scanned was a line feed or was the End Of File - EOF*/ printf("\n"); /*then print a line feed on screen */ fprintf(fp2,"\n"); /*and print a linefeed in the created file */ } }while(ch!=EOF); /*continue this loop as long as the EOF was not detected in the character scan*/ if((fclose(fp))!= 0) /*Close the opened file that fp points to, fclose will return a zero on completion. If this value isn't returned pint an error message*/ printf("Error closing newfile.txt!"); if((fclose(fp2))!= 0) /*Close the opened file that fp2 points to, fclose will return a zero on completion. If this value isn't returned pint an error message*/ printf("Error closing myfile.txt!"); return 0; }