Please help run all the examples correctly and only the examples without extra things in or less things in, it should run EXACTLY 100% like the examples. C language ONLY. And please dont reply if you cant run all the examples given.
We know the tr command allows you to replace or translate characters in of a stream. It takes in two arguments - a set of characters to be replaced and a set of replacement characters. The full functionality of the command can be found using man tr, but this problem only requires a basic implementation capable of solving the examples below.
Write a program that implements basic tr functionality. Your program should take two arguments - the set of characters to be replaced and a set of replacement characters. It should then read one line of input from the standard in and translate it as shown in examples below.
Example 1
$ ./tr abc def
Input
abc aabbcc aaabbbccc
Output
def ddeeff dddeeefff
Example 2
$ ./tr xy XY
Input
xxyyxx Lorem ipsum dolor sit amet xxyyxx
Output
XXYYXX Lorem ipsum dolor sit amet XXYYXX
Example 3
$ ./tr ab xyz
Output
Invalid arguments
Example 4
$ ./tr
Output
No arguments
Example 5
$ ./tr abc
Output
Not enough arguments
Example 6
$ ./tr abc def ghi
Output
Too many arguments
a tutor did this below code but it doesnt even run properly and he has put information that are not even part of the examples given :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CHARS 100
int main(int argc, char* argv[]) {
//printf("no. of arguments: %d\n",argc);
char* characters_to_be_replaced=argv[1]; //characters to be
replaced
char* replacement_characters=argv[2]; //replacement
characters
//int
num_characters_to_be_replaced=strlen(characters_to_be_replaced);
//int
num_replacement_characters=strlen(replacement_characters);
//printf("characters to be replaced:%s,
length:%d\n",characters_to_be_replaced,strlen(characters_to_be_replaced));
//printf("replacement
characters:%s\n",replacement_characters);
char input[MAX_CHARS],input_char,
replacement_char,output[MAX_CHARS];
int input_length=0,i;
printf("Input:\n");
fflush(stdout);
fgets(input, MAX_CHARS, stdin);
input_length=strlen(input);
//printf("input:%s,length:%d\n",input,input_length);
int found_at;
//printf("Processing input...\n");
for(i=0;i<input_length;i++)
{
input_char=input[i];
//printf("c:%c\n",input_char);
if(input_char!=' ')
{
char* ptr=strchr(characters_to_be_replaced,input_char);
if(ptr!=NULL)
{
//printf("found at:%d\n",ptr-characters_to_be_replaced);
found_at=ptr-characters_to_be_replaced;
//printf("read:%c,replacement:%c\n",input_char,*(replacement_characters+found_at));
replacement_char=*(replacement_characters+found_at);
}
output[i]=replacement_char;
}
else
{
//printf("input char:%c\n",input_char);
output[i]=input_char;
}
}
printf("Output:");
for(i=0;i<input_length;i++)
{
printf("%c",output[i]);
}
return EXIT_SUCCESS;
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Please help run all the examples correctly and only the examples without extra things in or...
In C Programming Adding to your program in part A, go through the command line arguments and find the largest and smallest arguments by alphabetical order. Note that you should not need to sort your arguments, but instead compare them and save the smallest and largest strings as you go through. For example, if called with ./reverse one two three: It would display the output for part A: Three two one And then it would display The smallest string was:...
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...
can someone help me with changing this to c++ language #include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <string.h> #include <dirent.h> #include <sys/wait.h> #include <time.h> #include <sys/stat.h> #include <unistd.h> char *pathLog; char *pathRep; struct stat attr; int fileNum, curNum; char *create_logPath(char *directory); void *funcChecker(void *pathSub); void *funcprintTimeAndChanges(void *pathSub); void main(int argc, char *argv[]) { if(argc < 3) { printf("%s must be executed with exactly two additional arguments (pathRep, pathSub)!\n", argv[0]); printf("Typed count is %d\n", argc); printf("Aborted...
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...
ANSWER ASAP PLEASE Using only the standard input/output function fgetc(), define a C function, called int readInt(int *value), that reads an integer from the keyboard (stdin), stores it in *value and, returns 1 for success or 0 for fail (in case the user enters nondigit characters). In particular, readInt() reads all characters, one by one, until a blank (or newline) is encountered. The string is then converted to an integer. It is also possible to have the sign charcater (+/-)...
The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...
I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...
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 programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...
Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...