Question: *the code:* #include #include #include #include #include /* ** Program 1 -- W Phillips ** ** This program was compiled and run on alpha.fdu.edu **


*the code:*
#include
#include
#include
#include
#include
/*
** Program 1 -- W Phillips
**
** This program was compiled and run on alpha.fdu.edu
** but it should work on any UNIX system.
**
** gcc Program1.c -o prog1
** prog1 i where i is a non negative int
** or
** prog1 ( A default value of 20 is assumed. )
*/
main (int argc, char* argv[])
{
int loopCount = 15;
int i;
int pNo = (int)getpid();
/*
** Check the argument list for errors.
*/
if ( argc
{
if ( argc == 2 )
{
loopCount = atoi(argv[1]);
if ( loopCount == 0 )
{
/*
** Determine if error or if the argument
** is zero. atoi returns zero in either
** case.
*/
int strLen = (int)strlen(argv[1]);
int err = 0;
for ( i = 0; i
if ( argv[1][i] != '0' )
{
err = 1;
break;
}
if ( err == 0 ) return 0; /* Zero means exit. */
}
if ( loopCount
{
/*
** Error in the argument. Inform the user.
*/
printf("Usage: sleepy i ( where i is an int >= 0 )");
printf(" or sleepy ");
return 0;
}
}
}
else
{
/*
** Error in number of arguments. There should only be
** zero or one arguments. Inform the user.
*/
printf("Invalid number of arguments. ");
printf("There should be 1 or 0 arguments ");
printf("Usage: sleepy i ( where i is an int >= 0 )");
printf(" or sleepy ");
return 0;
}
/*
** Argument was OK. Execute the sleep loop.
*/
/*
** YOU FILL IN THIS>
*/
printf("Count = %d ", loopCount);
return 0;
}
Write a program named fduello that gets an integer loop count from the command line as in fduhello n where n is the number of seconds that the program should run. Implement this by using a loop that iterates n times. The body of this loop will contain the statement sleep(1). This will result in the program sleeping for 1 second each time the loop executes. If no n value is given assume a default value of 15. Recall how to pass arguments via the command line: int main(int argc, char argv]) ine (count: 15;count =atoi (argv [1]); etc. sleep function (or look at man page): #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
