Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what I have so far: #include <fcntl.h> 2 #include <unistd.h> 3 #include

ID: 3555316 • Letter: T

Question

This is what I have so far:

#include <fcntl.h>
2 #include <unistd.h>
3 #include <studio.h>
4 #define BUF_SIZE 8
5
6 int main(int argc , char *argv[]) {
7
8 if (argc !=2)
9 {
10 printf("usage: %s filename", argv[0] );
11
12 }
13   
14 else {
15 FILE *ofp, *file1;
16 char *mode = "r","w";
17 char outputFilename[] = "out.list";
18 file1 = fopen(argv[1], "r");
19 ofp = fopen(argv[1], "w");
20 if (file1 == NULL || ofp == NILL)
21 {
22 printf("Couldn't open file");
23 exit (1);
24 }
25   
26 printf("Write ");
27 size_t read;
28
29   
30   
31 }

Explanation / Answer

#include <fcntl.h>
#include <unistd.h>
#include <studio.h>
#define BUF_SIZE 8

int main(int argc , char *argv[])
{
   char ch;
    if (argc !=2)
    {
       printf("usage: %s filename", argv[0] );
       printf("enter valid executable file name=argv[0] and output file name=argv[1] as command line parameters ");
       exit(0);
    }      
    else
   {
        FILE *ofp, *file1;
    //   char *mode = "r","w";
        char outputFilename[] = "out.list";
        file1 = fopen(argv[1], "r");
        if (file1 == NULL)
        {              
           printf("Couldn't open file");
            exit (1);
        }
        ofp = fopen(argv[1], "w");
        if (ofp == NULL)
        {              
           printf("Couldn't open file");
            exit (1);
        }
        printf("Write ");
        while(ch=getchar())
        {
            if(ch==26)   //if user enters Cntrl+z then exit
            {
                exit(0);
            }
            else
            {
                fputc(ch, ofp);
            }
        }
        size_t read;

    }
    fclose(ofp);
   fclose(file1);
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote