Subversion Repositories Kolibri OS

Rev

Rev 8730 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8687 turbocat 1
#include 
2
#include 
8730 turbocat 3
#include 
8787 turbocat 4
#include 
8687 turbocat 5
 
8730 turbocat 6
#define READ_MAX 255
7
 
8
static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz";
9
static char test_str2[READ_MAX];
10
 
8687 turbocat 11
int main(int argc, char **argv)
12
{
8730 turbocat 13
  int i=0;
8687 turbocat 14
  FILE *f;
15
 
16
  //write to file
8730 turbocat 17
  debug_printf("Write file...\n");
8687 turbocat 18
  f=fopen("testfile.txt","w");
19
 
8730 turbocat 20
  while(test_str1[i]!='a'){
21
    fputc(test_str1[i],f);
22
    i++;
8687 turbocat 23
  }
24
  fclose(f);
25
 
26
  //append to file
8730 turbocat 27
  debug_printf("Apend file...\n");
8687 turbocat 28
  f=fopen("testfile.txt","a");
8730 turbocat 29
  fputs(test_str1+i,f);
30
  char null_term = '\0';
31
  fwrite(&null_term, sizeof(char), 1, f);
8787 turbocat 32
  printf("Error: %s\n",strerror(errno));
8730 turbocat 33
  fclose(f);
8687 turbocat 34
 
8730 turbocat 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
40
    fputc(test_str2[i], stdout);
41
    i++;
8687 turbocat 42
  }
8730 turbocat 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
  }
8687 turbocat 49
  fclose(f);
8730 turbocat 50
}