Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int

Convert C to C++

I need these 4 C file code convert to C++. Please Convert it to C++

//////first C file: Wunzip.c

#include

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

if(argc ==1){

printf("wunzip: file1 [file2 ...] ");

return 1;

}

else{

for(int i =1; i< argc;i++){

int num=-1;

int numout=-1;

int c;

int c1;

FILE* file = fopen(argv[i],"rb");

if(file == NULL){

printf("Cannot Open File ");

return 1;

}

else{

while(numout != 0){

numout = fread(&num, sizeof(int), 1, file);

c = fread(&c1, sizeof(char), 1, file);

if(c!= 0){

for(int a =0;a< num;a++){

printf("%c",c1);

}}

}

}

fclose(file);

}

return 0;

}

}

/// Second C 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< argc;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;

}

///////Third C 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;

}

/////////Four C file: wzip.c

#include

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

char currentC;

char previousC;

int count = 1;

int stop =1;

if(argc == 1 ){

printf( "wzip: file1 [file2 ...] ");

return 1;

}

else{

for(int i =1;i

FILE *file = fopen(argv[i],"r") ;

if(file == NULL){

printf("wzip: cannot open file ");

return 1;

}

else{

previousC = fgetc(file);

// FILE *file1 = fopen("newfile","w") ;

while((currentC = fgetc(file)) != EOF){

if(previousC == currentC){

count++;

}

else{

fwrite(&count, 4, 1, stdout);

fwrite(&previousC, sizeof(char), 1, stdout);

previousC = currentC;

count =1;

}

}

fwrite(&count, 4, 1, stdout);

fwrite(&previousC, sizeof(char), 1, stdout);

}

fclose(file);

}

return 0;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Compare lean suppliers to traditional manufacturing suppliers.

Answered: 1 week ago

Question

what has dramatically reduced fatal childhood diseases in canada?

Answered: 1 week ago