I wrote the following code in order to write some random characters to a text file:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main()
{
int input_f = open("./input.txt", O_CREAT | O_APPEND | O_RDWR ,0666);
int i;
for(i=0;i<50;i++)
{
int r = rand()%252;
printf("%d size of r: %d\n",i,sizeof(r));
write(input_f,r,sizeof(r));
printf("%d we just wrote %d which is %c\n",i,r,r);
}
close(input_f);
}
I looked for some solutions to do this
Maybe someone here knows how can I fix this?
openandwriteand writing an error message if they fail. (man perrorandman strerror)writewould give it away as well.