Hey, hi, im very new to c programming and im jus learning file system calls. I have these 2 programs but cant seem to get them to run (see below) if you could take a quick look and tell me what ive done wrong. I found these programs on the internet and am just getting my head around it. If you could comment and tell me what each line does it would be helpful and what the program could be used for
Code:
/*Program 1*/
#include <fcntl.h>
main()
{
int fd;
fd = open("in1", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if(fd < 0)
{
perror("filename");
exit(1);
}
}
/**********************************************/
/*Program 2*/
#include <fcntl.h>
main()
{
char *c;
int fd, sz;
c = (char *) calloc(100, sizeof(char));
fd = open("in1", O_RDONLY);
if (fd < 0)
{
perror("filename");
exit(1);
}
sz = read(fd, c, 10);
c[sz] = '\0';
sz = read(fd, c, 99);
c[sz] = '\0';
close(fd);
}
Code tags added by Hammer