Question

implement the following function: void BuildString(int argc, char* argv[]); 1. Arguments passed through the function. Concatenate...

implement the following function:

void BuildString(int argc, char* argv[]);

1. Arguments passed through the function. Concatenate the strings arguments using strcat, display the concatenated string.

2.. If only one argument passed, display the string.

3. If no argument passed, display the message, no argument passed.
In main do the following:

1. Call the function BuildString, passing the proper arguments (argc and argv).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
int i, length = 0;
char str[100];
if( argc >= 2 )
{
strcpy(str, "");
for(i = 1; i < argc; i++)
{
strcat(str, argv[i]);
}
length = strlen(str);
str[length] = '\0';
printf("Final String: %s\n", str);
}
else
{
printf("argument list is empty.\n");
}
return 0;
}

Output:

Final String: ab


Add a comment
Know the answer?
Add Answer to:
implement the following function: void BuildString(int argc, char* argv[]); 1. Arguments passed through the function. Concatenate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc...

    The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc is greater or equal to 3. • If it is not, then print the following message: Incorrect number of arguments - please call with assignment min max where assignment is the name of your executable and min/max define the range of numbers for your array. • If argc is ≥ 3 convert the values for min and max into integers and store them in...

  • #include <stdio.h> int main(int argc, char *argv[]) { int i; for (i = argc - 1;...

    #include <stdio.h> int main(int argc, char *argv[]) { int i; for (i = argc - 1; i > 0; i--) printf("%s ", argv[i]); printf("\n"); return 0; } can you explain this code in c and why use this function  

  • #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc...

    #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...

  • The operating system is Ubuntu 18.04 hello.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello...

    The operating system is Ubuntu 18.04 hello.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello world!\n"); return 0; } syscall-hello.c #include <unistd.h> #include <sys/syscall.h> char *buf = "Hello world!\n"; int main(int argc, char *argv) { size_t result; /* "man 2 write" to see arguments to write syscall */ result = syscall(SYS_write, 1, buf, 13); return (int) result; }Download and compile hello.ce and syscall-hello.com. Compile them statically and dynamically. How do the library and system calls produced by them compare...

  • C++. i have a function bool get(int argc, char* argv[], option& opt) ./a.out -a123 -b 56s...

    C++. i have a function bool get(int argc, char* argv[], option& opt) ./a.out -a123 -b 56s -call -0 -uabs these are the arguments i want to erase the first character '-' and store the output in the option and value string variables. output will be: option: = a value : = 123 option: = b value: = 56s option: = c value := all option : = 0 option: = u value : = abs

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • C programming The program will require the following structure: struct _data { char *name; long number;...

    C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...

  • #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='...

    #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='z';      pc=&(c[8]);      pk=&(k[0]);      for (i=0; i<9; i++)     {           *pc=a-(char)i;           pc--;           *pk=(int)a-i;           pk++;           }                     return 0; }//end of main Answer the below questions with the above code Write out the memory map for the above C code in the following table. For array variables, list the address range for the entire array. Assume the memory address starts from 100, that is, the address for a...

  • Programing In C Add Command Line Arguments (Argc and Argv) and use files to the following...

    Programing In C Add Command Line Arguments (Argc and Argv) and use files to the following program. My program is called Ultimo.exe and it is in (C:\Users\Dell\source\repos\Ultimo\Debug). The file used is a .txt file in the directory of the .exe program. The text file which is address.txt is at the same location as Ultimo.exe (C:\Users\Dell\source\repos\Ultimo\Debug). The program takes information in the address.txt file and sorts it by zip code, from smallest to largest. The program works by using input/output redirection...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT