Write a program in C that takes a file name as the only argument on the command line, and prints out the number of 0-bits and 1-bits in the file
int main ( int argc , char * argv [] ) {
// Check if the user gave an argument , otherwise print " ERROR : no argument "
// Check if the file can be read , otherwise print " ERROR : can ’t read "
// Otherwise , use a loop to read each character of the file // For each character count the number of 0: s and 1: s .
// Print out the total number of 0: s and 1: s in the file , as a decimal number
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *filePtr;
char ch;
int countZero = 0;
int countOne = 0;
if(argc < 2) // 1st argument is: argv[0] = ./a.out, argv[1] =
fileName.txt
printf("ERROR : no argument");
else
{
// number of argument is correct; check if file can be read
filePtr = fopen(argv[1], "r");
if (filePtr == NULL)
{
printf("ERROR : file can't be read %s\n", argv[1]);
exit(0);
}
// file can be read
ch = fgetc(filePtr);
while(ch != EOF)
{
if(ch == '0')
countZero++;
else if(ch == '1')
countOne++;
ch = fgetc(filePtr);
}
fclose(filePtr);
// display the counts of zeros and ones in the file
printf("Number of 0's in the file: %d\n", countZero);
printf("Number of 1's in the file: %d\n", countOne);
}
return 0;
}
*************************************************************** SCREENSHOT ************************************************************
CONSOLE OUTPUT:

INPUT FILE: (input.txt)

Write a program in C that takes a file name as the only argument on the...
Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...
Modify When executing on the command line having only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with your new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the command line to be tested...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...
T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer is true or false in order to receive credit. #include <stdio.h> #include <string.h> int run_through(int num, char **a) { int i; int check=0; for(i=0;i<num;i++) { printf("%s\n", *(a+i)); if(strcmp(*(a+i), "filename")==0) { check=1; } } return check; } char** find_filename(int n, char **b) { int i; int check=0; for(i=0;i<n;i++) { if(strcmp(*b, "filename")==0) { b++; break; } b++; } return b; } int main(int argc, char **argv)...
If you already answer this question, please skip, thanks C Programming. Fill in ... This program will be called with one command line argument that contains a string followed by an asterisk and an integer. Print out the string as many time as indicated by the integer. For example, when called as prog Hi*3, you print HiHiHi. Hint: Look for the '*' starting from the back of the string. len = strlen(arg) gives you the string length. When you have...
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...
GIVEN CODE. PLEASE FILL IN THE
BLANK.
// Include Block
#include <fcntl.h>
#include <unistd.h>
// Preprocessor declarations
#define BUF_SIZE 10 /* global constant buffer size: Generally this
would be much larger, but I want to show you that it works in a
loop until the entire file is read.*/
// main function
int main(int argc, char *argv[])
{
// Variable declarations
int fd;
// file descripter
char buffer[BUF_SIZE];
// string for...
I need only one C++ function . It's C++ don't
write any other language.
Hello I need unzip function here is my zip function
below. So I need the opposite function unzip.
Instructions:
The next tools you will build come in a pair, because
one (zip) is a file compression tool, and
the other (unzip) is a file decompression
tool.
The type of compression used here is a simple form of
compression called run-length encoding (RLE). RLE is quite simple:
when...
need this in c programming and you can edit the code below. also
give me screenshot of the output
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define LINE_SIZE 1024
void my_error(char *s)
{
fprintf(stderr, "Error: %s\n", s);
perror("errno");
exit(-1);
}
// This funciton prints lines (in a file) that contain string
s.
// assume all lines has at most (LINE_SIZE - 2) ASCII
characters.
//
// Functions that may be called in this function:
// fopen(), fclose(), fgets(), fputs(),...