Question

Write and show how you would compile and run a C program that uses command line...

Write and show how you would compile and run a C program that uses command line arguments in the terminal.

Homework Answers

Answer #1

Program:

#include <stdio.h>

int main(int argc, char** argv)
{
int i;
printf("Give command line args: \n");
  
for (i = 1; i < argc; ++i)
printf("%s ",argv[i]);
  
return 0;
}

We will compile program and runs , Hello World Good morning are argument and a.out is program name

Compile:

g++ main.c

Run:

$./main Hello World Good morning
Know the answer?
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
Similar Questions
In Java, Write a small program that gets some numbers as command line arguments and finds...
In Java, Write a small program that gets some numbers as command line arguments and finds the minimum of those numbers. You can assume that the user will provide some command line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 8.25.
How to use command line argument in python to write a program implement linux command 'find'?
How to use command line argument in python to write a program implement linux command 'find'?
Write a C program that creates (or spawns) a child process to execute the Unix's command...
Write a C program that creates (or spawns) a child process to execute the Unix's command (echo) with a string as the command-line argument; while the program itself (the parent process) will execute another Unix command less with a filename as the command-line argument. If you aren't sure how the echo and less commands are meant to behave, experiment with them by running them directly from the command line first.
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line...
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print hello world and then exit(0). Otherwise, the program should provide a function named mm_alloc. This is the function prototype: void *mm_alloc(int num_bytes_to_allocate) mm_alloc function should obtain space for the user from a block which you obtain via mmap. You should obtain the block on the first invocation and the block size should be some number...
Compile and run the following code and presuming your executable is in a.out, run this command...
Compile and run the following code and presuming your executable is in a.out, run this command from the shell prompt: ./a.out ; echo "Parent Terminated Normally with a return value of $?" Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Hint: This has everything to do with how processes “communicate” their exit...
write a C program that takes a floating-point value from the command line. This value is...
write a C program that takes a floating-point value from the command line. This value is interpreted to be a fuel consumption reading in Miles/Gallon. The program returns the fuel consumption in Liters per 100 Kilometer. The prototype declaration of the function implementing this looks like this: float mpg_to_lp100k(float mpg);
Write a C program that runs on ocelot for a mini calculator using only the command...
Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line. The calculator will only do addition, subtraction, multiplication, division, and a power of 2. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-x] value • The variable value is the starting value. • Value should be validated to be an integer between 1 and 50 inclusive. Error message and usage shown...
Write a C Language program called iam.c to: Have a string variable called myName initialized to...
Write a C Language program called iam.c to: Have a string variable called myName initialized to your-name-here.  Print on one line a literal string "Hello " concatenated to myName. In Linux Terminal compile your iam.c source code program to produce a .exe executable. Run your iam.exe and take a print screen image. Upload your iam.exe file here.
Your program, called should take two command line arguments, the dictionary, and the text that you...
Your program, called should take two command line arguments, the dictionary, and the text that you wish to spellcheck. Provide some sample text. Your program should be case insensitive (so you can toLower everything). Numbers and contractions are considered valid words. You may use the java HashTable or HashMap to implement this program; but it must use some kind of hash table.
Q.6) What does it mean if you compile your C# source code file and you only...
Q.6) What does it mean if you compile your C# source code file and you only get copyright information about Microsoft as a response? a) You have not set the path to the compiler correctly. b) Your program has syntax errors that you must correct before you can compile the program. c) The compiler cannot find the source code file that you are trying to compile. d) The compiler successfully compiled your program. Q.4) To compile a C# source code...