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 ...]\n");
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\n");
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 ...]\n");
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\n");
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\n");
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 ...]\n");
return 1;
}
else{
for(int i =1;i
FILE *file = fopen(argv[i],"r") ;
if(file == NULL){
printf("wzip: cannot open file\n");
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;
}
}
The that you have made is a basic C program that is almost the same like C++ for proper conversion you have to change the header file and some standard output command printf to cout. control follow statement and loops are written in same as C in c++.
//////first C file: Wunzip.c
#include<bits/stdc++.h>//Header file for almost all
standard library in cpp
using namespace std;//all the standard function like count cin etc
are availabe in this group
int main(int argc, char* argv[])
{
if(argc == 1){
cout<<"wunzip: file1 [file2 ...]\n";
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){
//cout instead of printf is used in c++
cout<<"Cannot Open File\n";
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++){
/*cout
instead of printf is used in c++ and it
doesn't
use identifier like "%d" that we use in printf*/
cout<<c1;
}
}
}
}
fclose(file);
}
return 0;
}
}
/// Second C file: wgrep.c
#include<bits/stdc++.h>//Header file for almost all
standard library in cpp
using namespace std;//all the standard function like count cin etc
are availabe in this group
int main(int argc, char* argv[]) {
if(argc == 1){
cout<<"wgrep: searchterm [file ...]\n";
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])){
/*cout instead of printf is used in c++ and it
doesn't use identifier like "%d" that we use in
printf*/
cout<<output;
counter++;
}
}
return 0;
}
else{
for(int i =2;i< argc;i++){
FILE *file = fopen(argv[i], "r");
if (file == NULL){
//cout instead of printf is used in c++
cout<<"wgrep: cannot open file\n";
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])){
/*cout instead of printf is used in c++ and it
doesn't use identifier like "%d" that we use in
printf*/
cout<<output;
}
counter++;
}
fclose(file);
free(output);
output = NULL;
len = 0;
}
}
return 0;
}
///////Third C file: wcat.c
#include<bits/stdc++.h>//Header file for almost all
standard library in cpp
using namespace std;//all the standard function like count cin etc
are availabe in this group
int main(int argc, char* argv[]) {
if(argc == 1){
return 0;
}
//implementing Wcat
for(int i =1;i< argc;i++){
char totalBuf[100];
FILE *myFile = fopen(argv[i],
"r");
if (myFile == NULL) {
cout<<"wcat: cannot open file\n";
return 1;
}
while(fgets(totalBuf, 100, myFile)
!= NULL){
cout<<totalBuf;
}
fclose(myFile);
}
return 0;
}
/////////Four C file: wzip.c
#include<bits/stdc++.h>//Header file for almost all
standard library in cpp
using namespace std;//all the standard function like count cin etc
are availabe in this group
int main(int argc, char* argv[]) {
char currentC;
char previousC;
int count = 1;
int stop =1;
if(argc == 1 ){
cout<<"wzip: file1 [file2 ...]\n";
return 1;}
else{for(int i =1;i< argc;i++){
FILE *file = fopen(argv[i],"r")
;
if(file == NULL){
cout<<"wzip: cannot
open file\n";
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;
}
}
Screenshot of code


Note:- Because I don't have the input file, I can't show you result or output
Convert C to C++ I need these 4 C file code convert to C++. Please Convert...
My question is listed the below please any help this assignment ; There is a skeleton code: copy_file_01.c #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { char ch ; FILE *source , *target; if(argc != 3){ printf ("Usage: copy file1 file2"); exit(EXIT_FAILURE); } source = fopen(argv[1], "r"); if (source == NULL) { printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } target = fopen(argv[2], "w"); if (target == NULL) { fclose(source); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while ((ch...
Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the command line to be tested for file open.” Append to the program to output to the text log file a new line starting with day time date followed by the message "SUCCESSFUL". Append that message to a file “7Error_Log_File.txt” . ?newline Remember to be using fprintf using stderr using return using exit statements. Test for file existence, test 7NoInputFileResponse.txt file not null (if null...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
The program is done in C. This program opens a file containing binary or text and reads every byte in the file and writes both the ASCII hex value for that byte as well as it’s printable (human-readable) character (characters, digits, symbols) to standard output. The issue I am having is when the file has multiple lines being read. The first line is read and done properly but the other lines do not work correctly. For instance, the text file...
This question has been asked before but the responses have been wrong. Please do not copy and paste their answers. Currently the program opens a file and reads every byte in the file and write both the ASCII hex value for that byte as well as it’s printable character to standard output with non-printable characters printing a "." Now, I want have an option where the program prints in binary instead of hex by typing "-b" at the command line....
URGENT. Need help editing some C code. I have done most of the code it just needs the following added: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from the...
How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...
I JUST NEED HELP WITH DISPLAY PART!
please help!
thanks in advance
// This function saves the array of structures to file. It is already implemented for you.
// You should understand how this code works so that you know how to use it for future assignments.
void save(char* fileName)
{
FILE* file;
int i;
file = fopen(fileName, "wb");
fwrite(&count, sizeof(count), 1, file);
for (i = 0; i < count; i++)
{
fwrite(list[i].name, sizeof(list[i].name), 1, file);
fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...
In Programming language C - How would I convert my words char array into a string array so I can use the strcmp() function and alphabetically sort the words? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]){ int i =0; int j =0; int count =0; int length = strlen(argv[1]); for(i =0; i < length; i++){ if(isalpha(argv[1][i]) == 0 ||isdigit(argv[1][i] != 0)){ count ++; } printf("%c",argv[1][i]); } char *strings; int wordNum =0; int charNum =0; strings...
Below is a basic implementation of the Linux command "cat". This command is used to print the contents of a file on the console/terminal window. #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) {FILE *fp; if(2 != argc) {priritf ("Usage: cat <filename>\n"); exit(1);} if ((fp = fopen(argv[1], "r")) == NULL) {fprintf (stderr, "Can't. open input file %s\n", argv[1]); exit (1);} char buffer[256]; while (fgets(X, 256, fp) != NULL) fprintf(Y, "%s", buffer); fclose(Z); return 0;} Which one of the following...