Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Name csC 338 Parallel and Distributed Computing Exercise No. 2 C Programming Language Review Goal Review C Programming in Linux - command line arguments, File

image text in transcribed

Name csC 338 Parallel and Distributed Computing Exercise No. 2 C Programming Language Review Goal Review C Programming in Linux - command line arguments, File IO, pointers, loops, strings, malloc. Write a C program Ex02.c that performs one of the four operations based on command line arguments to the program. Please DO NOT use string libraries on this assignment. The possible command line options and the associated operations are as follows: Procedure Option "-a 12 30": read two integers from the command line arguments and output the sum of the two integers Example: -/Ex02 -a 12 30 o Output: 42 Option "-f ": read a file and output the content of the file Example: ./Ex02 -f Ex02.c. o Output: Option "-s ": output the combined 2 strings from the command line by using pointers. o Example: ./Ex02 -s hello world Output: helloworld Hint: A C type string is an array of char with the length of the number of characters plus a null character. For example: "hello" in C is stored as 'h''e''1''l''o'' ' which makes the "hello" array with the length of 6. You can declare a large new char array and use pointers to copy stringl and then string2 Declare a local variable or array will request memory space in automatic memory space "stack". Option "-m ": output the combined 2 strings by using dynamic memory allocation malloc. Example: . /Ex02 -s hello CSC338 Output: helloCSC338 Hint: "hello" contains 5 char plus '. "CSC338" contains 6 chars plus '. Therefore, you need to use malloc to create a new string with an array of 5+6+1 = 12 te be able to hold the combined string "hellocSC338" malloc will allocate memory space in free memory space "heap". bles en in a snapshot of your program's output on Blackboard (The output should contain the resul anning your program with the 4 options.). n in your source code of Ex02.c of

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_2

Step: 3

blur-text-image_3

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

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students explore these related Databases questions

Question

1. Identify three approaches to culture.

Answered: 3 weeks ago