Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help these are 2 C++ functions and I need these functions to C I need this all C++ code converting to C Please convert

Please help

these are 2 C++ functions and I need these functions to C

I need this all C++ code converting to C

Please convert this code to C

The code for the my-zip program is:

#include #include #include using namespace std;

void runlength_encoding(string content){ int size_ = content.length(); // size of the content in files

// the function uses simple logic to count continuous occurences of all characters and print them in standard output for (int i = 0; i < size_ ; i++) { char cur_char = content[i]; int count = 1; while (i < size_ - 1 && content[i] == content[i + 1]) { count++; i++; } // writing in binary using fwrite fwrite(&count , sizeof(int) ,1 , stdout ); cout<

int main(int argc, char **argv){ if(argc<=1){ // incase no file is specified following the guide lines mentioned cout<<"my-zip:file1[file2..] "; exit(1); } string all_content = ""; for(int i = 1; i(file)),istreambuf_iterator()); all_content+=content; } //calling runlength encoding function runlength_encoding(all_content); }

The code for th my-unzip is:

#include using namespace std;

int main(int argc, char **argv){ if(argc<=1){ // incase no file is specified cout<<"my-unzip:file1[file2..] "; exit(1); } FILE *fp; // file pointer fp = fopen(argv[1], "rb"); if(fp == NULL) {

// in case the file does not exist printf("Error opening file "); exit(1); }

//runlength_decoding

int count; char c;

while(fread(&count , sizeof(int), 1 , fp) == 1){ fread(&c , sizeof(char), 1 ,fp); // reading character and the number of times it occurs continuously in c and count // then printing it that many times in standard output console for(int i=0;i

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

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions