Question: #include #include #include #include #include #include #include //using namespace std; char script[600]; int main( int argc, char** argv ) { int j; char data[600]; //cout

#include #include #include #include #include #include #include

//using namespace std; char script[600];

int main( int argc, char** argv ) { int j; char data[600]; //cout << "You have entered " << argc-1 << " arguments:"; for (j = 1; j < argc; ++j) { sprintf(script, "%s %s", "cat ", argv[j]); // content stored as a C string in the buffer pointed by str. printf(" ***************Start of File******************* "); system(script); // system call to execute the command printf(" *******************End Of File******************* "); return 0; } //int open(const char *pathname, int flags); int fd,fd1,fd2;//declaring all three here fd = open("path_to_a_file", O_RDWR | O_CREAT, 0755); if(fd == -1) { perror("opening file"); } int close(int fd); char stringbuffer[1024];

fd1 = open("file1", O_RDONLY); ssize_t howmany, some_struct; howmany = read(fd1, stringbuffer, 1024); if(howmany==-1) { perror("reading file 1"); exit(1); } howmany = read(fd2, &data, sizeof(some_struct)); if(howmany==-1) { perror("reading file 2"); exit(2); } ssize_t write(int fd, const void *buf, size_t count); char mystring[] = "Some text to write."; char * pointer = (char *) mystring; fd1 = open("file1", O_WRONLY); fd2 = open("file2", O_WRONLY); // write the character array to file 1 howmany = write(fd1, mystring, sizeof(mystring)); if(howmany==-1) { perror("writing to file 1"); exit(1); } // sizeof gives the wrong answer for pointers, use strlen howmany = write(fd2, pointer, strlen(pointer)); if(howmany==-1) { perror("writing to file 2"); exit(2); } return 0; }

Getting "bad file descriptor" please help fix

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!