#include int main () { // Some variables: an int, a double, a char and a string. int i = 1; double x = 2.5; char ch = 'a'; char *str = "hello"; // A char array to hold input lines. char inputLine [100]; // Declare a file pointer. Note the capitalization. FILE *dataFile; // Open the file. dataFile = fopen ("data.txt", "w"); // Print the four variables. printf ("i = %d x=%lf ch=%c str = %s\n", i, x, ch, str); fprintf (dataFile, "i = %d x=%lf ch=%c str = %s\n", i, x, ch, str); // Write to file. // Scanning in numbers: printf ("Enter an integer followed by a double: "); scanf ("%d %lf", &i, &x); printf ("i = %d x = %lf\n", i, x); fprintf (dataFile, "i = %d x = %lf\n", i, x); // Write to file. // Scanning in a string: printf ("Enter a string: "); scanf ("%s", inputLine); printf ("You entered: %s\n", inputLine); fprintf (dataFile, "You entered: %s\n", inputLine); // Write to file. // Close the file. fclose (dataFile); }