Subversion Repositories Kolibri OS

Rev

Rev 8787 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5.  
  6. #define READ_MAX 255
  7.  
  8. static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz";
  9. static char test_str2[READ_MAX];
  10.  
  11. int main(int argc, char **argv)
  12. {
  13.   int i=0;
  14.   FILE *f;
  15.  
  16.   //write to file
  17.   debug_printf("Write file...\n");
  18.   f=fopen("testfile.txt","w");
  19.  
  20.   while(test_str1[i]!='a'){
  21.     fputc(test_str1[i],f);
  22.     i++;
  23.   }
  24.   fclose(f);
  25.  
  26.   //append to file
  27.   debug_printf("Apend file...\n");
  28.   f=fopen("testfile.txt","a");
  29.   fputs(test_str1+i,f);
  30.   char null_term = '\0';
  31.   fwrite(&null_term, sizeof(char), 1, f);
  32.   printf("Error: %s\n",strerror(errno));
  33.   fclose(f);
  34.  
  35.   //copy from testfile.txt to copyfile.txt
  36.   debug_printf("Read file...\n");
  37.   f=fopen("testfile.txt","r");
  38.   i=0;
  39.   while((test_str2[i]=fgetc(f))!=EOF && i<READ_MAX){
  40.     fputc(test_str2[i], stdout);
  41.     i++;
  42.   }
  43.   printf("\n%s\n", test_str1);
  44.   if(!strcmp(test_str2, test_str1)){
  45.     puts("TEST: OK!");
  46.   }else{
  47.     puts("TEST: FAIL!");
  48.   }
  49.   fclose(f);
  50. }
  51.