Question: Convert code to C++ Hi I need you to convert C to C++. I'm testing .sh file. Screenshot is below and is perfectly working on
Convert code to C++
Hi I need you to convert C to C++. I'm testing .sh file. Screenshot is below and is perfectly working on C. please convert C++.
/////First file: wcat.c
#include
int main(int argc, char* argv[]) {
if(argc == 1){
return 0;
}
//implementing Wcat
for(int i =1;i char totalBuf[100]; FILE *myFile = fopen(argv[i], "r"); if (myFile == NULL) { printf("wcat: cannot open file "); return 1; } while(fgets(totalBuf, 100, myFile) != NULL){ printf("%s",totalBuf); } fclose(myFile); } return 0; } ////////Second file: wgrep.c #include #include #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wgrep: searchterm [file ...] "); return 1; } else if(argc ==2){ size_t len = 0; ssize_t linesize=0; char* output = NULL; int counter =1; while((linesize = getline(&output, &len, stdin)) != -1){ if(strstr(output, argv[1])){ printf( "%s",output); counter++; } } return 0; } else{ for(int i =2;i FILE *file = fopen(argv[i], "r"); if (file == NULL){ printf("wgrep: cannot open file "); return 1; } size_t len = 0; ssize_t linesize=0; char* output = NULL; int counter =1; while((linesize = getline(&output, &len, file)) != -1){ if(strstr(output, argv[1])){ printf( "%s",output); } counter++; } fclose(file); free(output); output = NULL; len = 0; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
