Task One, Echo
Program Source code:
#include<stdio.h> #include<stdlib.h> #include<string.h>
intMainintargcChar*argv[]) {
int Nflag;
if (*++ARGV &&!strcmp (*ARGV, "-n"))
{
++ARGV;
Nflag = 1;
}
Else
Nflag = 0;
while (*ARGV)
{
printf ("%s", *ARGV);
if (*++ARGV) Putchar (");
}
if (!nflag) Putchar (' \ n ');
Exit (0);
}
|
Task Requirements:
This program is the source code for the Echo implementation of commands under UNIX (with appropriate deletions and adornments).
Please use the structured flowchart to draw the procedure in the main function of this program .
task Two, Sleep
Program Source code:
#include<sys/time.h> #include<time.h> #include<ctype.h> #include<math.h> #include<signal.h> #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<locale.h>
voidUsage () {
(void) fprintf (stderr, "Usage:sleep seconds\n");
Exit (1);
}
voidAlarmhandle () {
_exit (0);
}
intMainintargcChar *Argv[]) {
Char *arg, *temp;
Double Val, ival, fval;
struct timespec ntime;
int Fracflag;
int ch;
SetLocale (Lc_all, "");
(void) signal (SIGALRM, alarmhandle);
while (ch = getopt (argc, argv, ""))!! =-1)
Switch (CH) {
Case ‘?‘:
default:
Usage ();
}
ARGC-= Optind;
argv + = Optind;
if (argc! = 1) usage ();
Fracflag = 0;
arg = *ARGV;
for (temp = arg; *temp! = '); temp++)
if (!isdigit (*temp)) fracflag++;
if (Fracflag)
{
val = atof (ARG);
if (Val <= 0) exit (0);
Ival = Floor (val);
fval = (1000000000 * (Val-ival));
Ntime.tv_sec = ival;
Ntime.tv_nsec = fval;
}
Else {
Ntime.tv_sec = Atol (ARG);
if (ntime.tv_sec <= 0)
Exit (0);
ntime.tv_nsec = 0;
}
(void) Nanosleep (&ntime, NULL);
Exit (0);
}
|
Requirements:
This program is the source code for the sleep implementation of commands under UNIX (with appropriate deletions and adornments).
Please use the structured flowchart to draw the procedure in the main function of this program.
This article is from the "8403723" blog, please be sure to keep this source http://8413723.blog.51cto.com/8403723/1716117
C Language Beginner Drawing practice