2023-04-22 15:35:32 +03:00
|
|
|
#include <stdio.h>
|
2023-05-06 18:10:38 +03:00
|
|
|
#include <stdlib.h>
|
2023-04-22 15:35:32 +03:00
|
|
|
|
2023-05-09 20:31:22 +03:00
|
|
|
#define ERROR(msg) { perror(msg); return 1; }
|
|
|
|
#define BUF_SIZE 1024
|
2023-05-07 23:57:01 +03:00
|
|
|
|
2023-04-12 22:20:18 +03:00
|
|
|
int main()
|
|
|
|
{
|
2023-05-09 20:31:22 +03:00
|
|
|
FILE* fp = fopen("/usr/include/stdio.h", "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
ERROR("fopen");
|
|
|
|
|
|
|
|
char* buffer = malloc(BUF_SIZE);
|
|
|
|
if (buffer == NULL)
|
|
|
|
ERROR("malloc");
|
2023-05-07 23:57:01 +03:00
|
|
|
|
2023-05-09 20:31:22 +03:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
size_t n_read = fread(buffer, 1, BUF_SIZE - 1, fp);
|
|
|
|
if (n_read == 0)
|
|
|
|
break;
|
|
|
|
buffer[n_read] = '\0';
|
|
|
|
printf("%s", buffer);
|
2023-04-25 14:50:26 +03:00
|
|
|
}
|
2023-05-09 20:31:22 +03:00
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
fclose(fp);
|
|
|
|
|
2023-04-12 22:20:18 +03:00
|
|
|
return 0;
|
|
|
|
}
|