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

NEED help with the with a small portion of the program C PROGRAMMING #include<st

ID: 653567 • Letter: N

Question

NEED help with the with a small portion of the program

C PROGRAMMING

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char*argv[])
{
   FILE *inPtr;
   FILE *outPtr;
   int c;
   int i;

   if(argc != 3)
   {
       puts("Usage: arg1 arg2");
   }

   else
   {
       inPtr = fopen(argv[1], "r");
       if(!inPtr)
       {
           perror("File could not be opened for reading:");
           exit(1);
       }
       outPtr = fopen(argv[2], "w");
       if(!outPtr)
       {
           perror("File could not be opened for appending: ");
           exit(1);
       }
   }

   i = 0;

   printf("contents of outile.txt ");

   while((c = fgetc(inPtr)) != EOF)
   {
  

   // to print in outfile
   // NEEDS FIXING while(fgets(c, 10, inPtr))
      
  

       if( i %2 != 0)
           printf( "line %d ", i);
           //fprintf(outPtr, "line %d ", i);

           i++;
      
   }

   fclose(inPtr);
   fclose(outPtr);
   return EXIT_SUCCESS;


}

//this is my output

./2 infile.txt outfile.txt
contents of outile.txt
line 1
line 3
line 5
line 7
line 9
line 11
line 13
line 15
line 17
line 19
line 21
line 23
line 25
line 27
line 29

//sample output

$./lab11 infile.txt outfile.txt

contents of infile.txt

line1

line2

line3

line4

line5

contents of outfile.txt

line1

line3

line5

(infile.txt)

line1
line2
line3
line4
line5

Explanation / Answer

// to print output file

printf("%c",c);

// needs fixing

while(fgets(c,10,inPtr)!=NULL)

{

if(i%2!=0){ printf( "line %d ", i);}

}