I'm trying to implement low-level I/O using open, write, and read. The above code works fine but I can't seem to use read() to get the data back out. I'm using read() with the read only flag and using a char as a buffer. I'm trying to read the contents of the file into a character array and then print that to the screen.
Any ideas?
Code:#include <fcntl.h>
#include <stdio.h>
char str[80];
int i,f;
main()
{ f = open("abc",O_WRONLY|O_CREAT,0700);
printf("Enter a string: ");
fgets(str, 10, stdin);
i = strlen(str)-1;
if( str[ i ] == '\n')
str[i] = '\0';
write(f,str,80);
close(f);
}