Question

In: Computer Science

Construct two small C programs, compile and set up two executable files for the two commands...

Construct two small C programs, compile and set up two executable files for the two commands world and mars. Both commands simply print out messages on the screen:

world n - print the message hello world on the screen n times

mars n - print the message HELLO MARS on the screen n times

Thanks a lot for your help!!!

Solutions

Expert Solution

world.c

#include <stdio.h> /*typically in /usr/include*/
#include <stdlib.h>

int main (int argc, char* argv [ ])
/*pass command line arguments from shell;
argc-number of parameters and argv[]—the arguments*/
{
   int count, i;
   if (argc != 2)
   {
      fprintf(stderr, "usage: %s count\n", argv[0]);
/* run as- hello world count*/
      exit (-1);
/*signal error (return other than 0) to shell*/
   }
   else
      count = atoi (argv[1]);

   for ( i = 0; i < count; i++ )
      printf("hello world!\n");

   return 0;
}


mars.c

#include <stdio.h> /*typically in /usr/include*/
#include <stdlib.h>

int main (int argc, char* argv [ ])
/*pass command line arguments from shell;
argc-numberof parameters and argv[]—the arguments*/
{
   int count, i;
   if (argc != 2)
   {
      fprintf(stderr, "usage: %s count\n", argv[0]);
/* run as- hello world count*/
      exit (-1);
/*signal error (return other than 0) to shell*/
   }
   else
      count = atoi (argv[1]);

   for ( i = 0; i < count; i++ )
      printf("Hello Mars!\n");

   return 0;
}


Related Solutions

Describe two advantages of using dynamically linked libraries in assembling executable program files.
Describe two advantages of using dynamically linked libraries in assembling executable program files.
Describe two advantages of using dynamically linked libraries in assembling executable program files.
Describe two advantages of using dynamically linked libraries in assembling executable program files.
compile and link two c programs from cmd prompt: using command gcc program1.c program2.h -o main...
compile and link two c programs from cmd prompt: using command gcc program1.c program2.h -o main but getting error undefined reference to scheduleFCFS not sure how to correct issue.
use the general activated sludge /anaerobic digestion model to set up biowin files
use the general activated sludge /anaerobic digestion model to set up biowin files
Suppose an elevator is controlled by two commands: ↑ to move the elevator up one floor...
Suppose an elevator is controlled by two commands: ↑ to move the elevator up one floor and ↓ to move the elevator down one floor. Assume that the building is arbitrarily tall and that the elevator starts at floor x. A)Write an LL(1) grammar that generates arbitrary command sequences that (1) never cause the elevator to go below floor x and (2) always return the elevator to floor x at the end of the sequence. For example, ↑↑↓↓ and ↑↓↑↓...
You are a small biotechnology firm and need the financialsupport and the set-up to perform...
You are a small biotechnology firm and need the financial support and the set-up to perform clinical trials on your formulas, what might be your best, and least risky, source of funding? Why?
You are about to set up a small business in the community service sector.
You are about to set up a small business in the community service sector. Consider the organisation's objectives and write a 3 page paper outlining the professional and ethical standards to which your organisation would adhere. Use your imagination to fill any caps.What external influences and data would inform the expectations you might have of your employees?Explain how you ensure that the employees working in the organisation continuously upgrade their skills and how would determine the developmental needs of your...
You have been hired as an IT expert by a small firm to set up an...
You have been hired as an IT expert by a small firm to set up an office for 20 staff members, half of whom will work with desktop computers and the remaining with laptop computers using wireless networks. The office would use one networked laser printer, accessible from both the desktop and laptop computers. The desktop computers will use a wired network, while the laptop computers will employ a wireless network to print and access the internet. Start making a...
Look up and use each of these Linux commands. (Each command will have two parts) Summarize...
Look up and use each of these Linux commands. (Each command will have two parts) Summarize their function then use the command Use the Command and document the output (<parameters of your choice> Command Function info cat Demonstrate 'cat' in use   man cp Demonstrate 'cp' in use   man touch Demonstrate 'touch' in use   man mv Demonstrate 'mv' in use   man rm Demonstrate 'rm' in use   info wc Demonstrate 'wc' in use   man find Demonstrate 'find' in use   man chmod Demonstrate...
Q1.You plan to set up a company, so construct a WBS for the project Q2. Explain...
Q1.You plan to set up a company, so construct a WBS for the project Q2. Explain the role of “ map of interdependencies ” in the WBS Q3. Give several examples of a type of project that would benefit from a template project action plan being developed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT