forked from KolibriOS/kolibrios
kolibri-libc:
- Added ungetc, tollower and toupper to export - Fixed ungetc emu - Fixed file io functions - Update file_io test git-svn-id: svn://kolibrios.org@8730 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,43 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define READ_MAX 255
|
||||
|
||||
static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz";
|
||||
static char test_str2[READ_MAX];
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
int i;
|
||||
char c;
|
||||
int i=0;
|
||||
FILE *f;
|
||||
FILE *fin;
|
||||
FILE *fout;
|
||||
|
||||
//write to file
|
||||
debug_printf("Write file...\n");
|
||||
f=fopen("testfile.txt","w");
|
||||
|
||||
for(i=0;i<50;i++)
|
||||
{
|
||||
fputc('1',f);
|
||||
while(test_str1[i]!='a'){
|
||||
fputc(test_str1[i],f);
|
||||
i++;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
//append to file
|
||||
debug_printf("Apend file...\n");
|
||||
f=fopen("testfile.txt","a");
|
||||
|
||||
for(i=0;i<50;i++)
|
||||
{
|
||||
fputc('2',f);
|
||||
}
|
||||
fputs(test_str1+i,f);
|
||||
char null_term = '\0';
|
||||
fwrite(&null_term, sizeof(char), 1, f);
|
||||
fclose(f);
|
||||
|
||||
//copy from testfile.txt to copyfile.txt
|
||||
|
||||
fin=fopen("testfile.txt","r");
|
||||
fout=fopen("copyfile.txt","w");
|
||||
/*
|
||||
while((c=fgetc(fin))!=EOF)
|
||||
{
|
||||
fputc(c,fout);
|
||||
}*/
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user