Files
kolibrios/programs/develop/ktcc/libc.obj/samples/file_io.c
T
ace-dentandBurer a4f3f3545a develop/ktcc: Post-SVN tidy (#425)
- Move source code from `trunk` into root directory.
- Update build files and ASM include paths. Add SPDX license header where appropriate.
- These changes also update the CI build files in `.gitea/workflows/`.
- Note: Line endings standardised from `CRLF` > `LF`, so best to view diffs with whitespace changes hidden.

(Work towards [#75](KolibriOS/kolibrios#75), point 3)

---------

Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#425
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@kolibrios.org>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2026-04-19 16:41:37 +00:00

51 lines
1.2 KiB
C

#include <errno.h>
#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 = 0;
FILE* f;
// write to file
debug_printf("Write file...\n");
f = fopen("testfile.txt", "w");
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");
fputs(test_str1 + i, f);
char null_term = '\0';
fwrite(&null_term, sizeof(char), 1, f);
printf("Error: %s\n", strerror(errno));
fclose(f);
// copy from testfile.txt to copyfile.txt
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);
}