cp ~pconrad/public_html/cis105/2003.fall/labs/lab12Code/lab12a.c .
/* a program that just demonstrates how to write output to a file */
#include <stdio.h>
int main ()
{
FILE *outfile; /* declare a file pointer */
int x=3; /* x and y are variables just for demonstration purposes */
double y=4.5;
/* open the output file */
outfile = fopen("lab12a.dat","w"); /* try to open file for writing */
if (outfile == NULL) /* check return status */
{
perror("File lab12a.dat could not be opened: "); /* print error */
exit(-1);
}
/* write some output to the file */
fprintf(outfile,"This output is going to the file lab12a.dat.\n");
printf("This output is going to the terminal.\n");
printf("I can still write to the terminal in the same program\n");
printf("that I am writing to a file.\n");
fprintf(outfile,"I can also print the value of variables to a file.\n");
fprintf(outfile,"for example, x=%d, y=%.2f\n",x,y);
fprintf(outfile,"Bye now!\n");
/* close the output file */
fclose(outfile);
return 0;
}
For Part1 of this lab, do the following steps. The result will be
a script file lab12a.txt, which you will submit.
ls
command, and note that there is no file called
lab12a.dat in your directory.
ls command and note that there
should now be a file called lab12a.dat in your
directory. Use cat lab12a.dat to list the output of
this file.
lab12a.c file to personalize the
message that is going to the file. Make it print your name to the
file as part of the message, along with any other pithy comments you
want to pass along to your TA and/or instructor.
rm command to delete lab12.dat
from your directory. Then, make a script file lab12a.txt
in which you
ls to show that there is no lab12a.dat
file in your directory, ls command
to show that lab12a.dat was created, lab12a.dat. To do this part of the lab, take the following steps.
lab12b.c) into your directory. The form of the command
is the same as the command for lab12a.c.
lab12a.c, you should do an ls command before and after you run the program to see what files are created. Use cat or more to see the contents of the files.
gnuplot lab12b.gnuplot to generate a file lab12b.png. Then, view the file, either by copying it into your public_html directory and using a web browser to view it, or, if you are on an X terminal, using the command xv lab12b.png.
mkdir ~/public_html/cis105). Copy your lab12b.png file into that subdirectory. Make both the subdirectory and the file world readable, so that the URL http://udel.edu/~youruserid/cis105/lab12b.png allows anyone who wants to (e.g. me and your TA) to see your resulting output file.