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

Question: Fix my my code in linux enviroment. (should be a couple line fix) ____

ID: 639045 • Letter: Q

Question

Question: Fix my my code in linux enviroment. (should be a couple line fix)

________________________________________________________

Question description:

________________________________________________________

Error message I get:

________________________________________________________

my Code attempt:

/* A sample file to read the contents of a file into a
character buffer.

*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(int argc, char** argv) {

printf ("Reading a file into a character buffer. ");

// Verify that a file name is provided and that the file exists.
// Use some new C++ stream features.
if (argc <= 1) {
printf ("Usage: readInput ") ;
return 1 ;
}

printf ("Opening file "%s". ", argv[1]);

FILE *in_fp ;
in_fp = fopen(argv[1],"r") ;
if ( in_fp==NULL ) {
printf ("File "%s" not found. ", argv[1]);
return 2 ;
}
// Determine the size of the file, used to allocate the char buffer.
struct stat filestatus;
stat( argv[1], &filestatus );

int filesize = filestatus.st_size + 1; // +1 for terminating null char

// Allocate space for the character buffer.
char *buffer = (char *) malloc( sizeof(char) * filesize ) ;

int index = 0 ;
char ch = getc(in_fp) ;

while (ch != EOF) {
buffer[index] = ch ;
index ++ ;
ch = getc(in_fp);
}
buffer[index] = '' ;
  
int totalSLetterCount=0;
for(int i=0;buffer[i]!='';i++)
{
   if(buffer[i]=='s'||buffer[i]=='S')
   {
       totalSLetterCount++;
   }
}
printf("Total s letters count is : %d ",totalSLetterCount);

return 0 ;
}

Explanation / Answer

you given c program...but why you are executing file with extension with .cpp

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