home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / c_interp / Examples / stdio < prev    next >
Encoding:
Text File  |  1993-12-13  |  577 b   |  35 lines

  1. @* An example of some stdio library routines *@
  2.  
  3. main()
  4. {
  5. char text[40];
  6. int fileptr, i;
  7.  
  8. bbc_mode(12);
  9.  
  10. sprintf(text,">>TEXT<<");
  11. printf("This is a simple stdio test program: %s\n",text);
  12.  
  13. fileptr = fopen("testfile","w");
  14. if(!fileptr)
  15.   puts("Can't open output file!");
  16. else
  17.   {
  18.   for(i=0; i<20; i++)
  19.     {
  20.     fprintf(fileptr,"\nThis is some text in a file (line %d).",i+1);
  21.     }
  22.   fclose(fileptr);
  23.   }
  24.  
  25. for(fileptr=fopen("testfile","r"); !feof(fileptr);)
  26.   {
  27.   fgets(text,39,fileptr);
  28.   if(!feof(fileptr))
  29.     printf("%s",text);
  30.   }
  31. fclose(fileptr);
  32.  
  33. remove("testfile");
  34. }
  35.