programming with c language (7)

/*
 program to write into a file some variables and constants
 then reading from the file to display to screen
*/
#include<stdio.h>

float price[]={25.20,100.00,8.95}, cost;
char *description[]={"Pencils","Pens","Erasers"};
char desc[10];

main(){
 int i;
 FILE *f, *fopen();
 f=fopen("prices","w");
 fprintf(f,"Nicholas \n");
 for(i=0;i<3;i++)
  fprintf(f, "%9s %6.2f\n", description[i],price[i]);
 fclose(f);

 f=fopen("prices","r");
 fscanf(f,"%s",desc);
 while(fscanf(f,"%s %f", desc,&cost) != EOF)
   printf("%9s %6.2f\n", \
    desc,cost);
 fclose(f);
}
 

Click here to go back to 'C' programming
If you have comments or suggestions, email me at nicholas@tm.net.my

This page created with Netscape Navigator Gold (17/9/1999)