on execution, file creation is working well...but nothing gets written into it...what could be done...is there any other way apart from using file descriptors..??
I tried the following code:
memset(buffer, '\0', sizeof(buffer));
read_fp = popen("gcc test1.c", "r");
//fp = fopen("/home/pranav/Desktop/b4.txt","w");
fd = open("beejoutput2.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (read_fp != NULL)
{
chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
while (chars_read > 0)
{
/*writing to the file*/
while ((bytesread = read(3, buffer, chars_read)) > 0)
write(fd, buffer, bytesread);
buffer[chars_read-1] = '\0';
printf("Reading %d:-\n %s\n", BUFSIZ, buffer);
//fprintf(fp,"%d:-\n %s\n", BUFSIZ, buffer);
chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
}
pclose(read_fp);
exit(EXIT_SUCCESS);
}
//fclose(fp);
exit(EXIT_FAILURE);
return 0;
}