2021-04-27 18:33:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-05-23 17:28:07 +02:00
|
|
|
#include <string.h>
|
2021-06-09 05:17:46 +02:00
|
|
|
#include <errno.h>
|
2021-05-23 17:28:07 +02:00
|
|
|
|
|
|
|
#define READ_MAX 255
|
|
|
|
|
|
|
|
static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz";
|
|
|
|
static char test_str2[READ_MAX];
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2021-05-23 17:28:07 +02:00
|
|
|
int i=0;
|
2021-04-27 18:33:31 +02:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
//write to file
|
2021-05-23 17:28:07 +02:00
|
|
|
debug_printf("Write file...\n");
|
2021-04-27 18:33:31 +02:00
|
|
|
f=fopen("testfile.txt","w");
|
|
|
|
|
2021-05-23 17:28:07 +02:00
|
|
|
while(test_str1[i]!='a'){
|
|
|
|
fputc(test_str1[i],f);
|
|
|
|
i++;
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
//append to file
|
2021-05-23 17:28:07 +02:00
|
|
|
debug_printf("Apend file...\n");
|
2021-04-27 18:33:31 +02:00
|
|
|
f=fopen("testfile.txt","a");
|
2021-05-23 17:28:07 +02:00
|
|
|
fputs(test_str1+i,f);
|
|
|
|
char null_term = '\0';
|
|
|
|
fwrite(&null_term, sizeof(char), 1, f);
|
2021-06-09 05:17:46 +02:00
|
|
|
printf("Error: %s\n",strerror(errno));
|
2021-04-27 18:33:31 +02:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
//copy from testfile.txt to copyfile.txt
|
2021-05-23 17:28:07 +02:00
|
|
|
debug_printf("Read file...\n");
|
|
|
|
f=fopen("testfile.txt","r");
|
|
|
|
i=0;
|
|
|
|
while((test_str2[i]=fgetc(f))!=EOF && i<READ_MAX){
|
|
|
|
fputc(test_str2[i], stdout);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
printf("\n%s\n", test_str1);
|
|
|
|
if(!strcmp(test_str2, test_str1)){
|
|
|
|
puts("TEST: OK!");
|
|
|
|
}else{
|
|
|
|
puts("TEST: FAIL!");
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|