base for h3
This commit is contained in:
parent
c886752016
commit
c642a88fe6
14
334/homework/3/chap5.txt
Normal file
14
334/homework/3/chap5.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#
|
||||||
|
# Problem lines begin with "#@".
|
||||||
|
# For each problem line, enter your answer on the following line.
|
||||||
|
# Do not modify this file in any way except to enter your answers.
|
||||||
|
#
|
||||||
|
|
||||||
|
#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer)
|
||||||
|
b
|
||||||
|
#@ 2 -- enter 'a', 'b', or 'c'
|
||||||
|
a
|
||||||
|
#@ 3 -- enter 'a', 'b', or 'c'
|
||||||
|
b
|
||||||
|
#@ 4 -- enter 'a', 'b', or 'c'
|
||||||
|
a
|
14
334/homework/3/chap6.txt
Normal file
14
334/homework/3/chap6.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#
|
||||||
|
# Problem lines begin with "#@".
|
||||||
|
# For each problem line, enter your answer on the following line.
|
||||||
|
# Do not modify this file in any way except to enter your answers.
|
||||||
|
#
|
||||||
|
|
||||||
|
#@ 1 -- enter 'a' or 'b' (don't use quotes in any answer)
|
||||||
|
b
|
||||||
|
#@ 2 -- enter 'a', 'b', or 'c'
|
||||||
|
a
|
||||||
|
#@ 3 -- enter 'T' or 'F'
|
||||||
|
F
|
||||||
|
#@ 4 -- enter 'T' or 'F'
|
||||||
|
F
|
43
334/homework/3/msh.c
Normal file
43
334/homework/3/msh.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define PROMPT "msh> "
|
||||||
|
#define EXIT_CMD "exit"
|
||||||
|
#define MAX_BUF 121
|
||||||
|
|
||||||
|
void echo(const char*);
|
||||||
|
void remove_newline(char*);
|
||||||
|
void exit_branch(const char*);
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char buffer[MAX_BUF];
|
||||||
|
while(1) {
|
||||||
|
printf("%s", PROMPT);
|
||||||
|
fgets(buffer, MAX_BUF, stdin);
|
||||||
|
// process the input
|
||||||
|
remove_newline(buffer);
|
||||||
|
exit_branch(buffer);
|
||||||
|
echo(buffer);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void echo(const char* buf) {
|
||||||
|
printf("%s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void remove_newline(char* buf) {
|
||||||
|
char* c = buf;
|
||||||
|
while(*c != '\n') { c++; }
|
||||||
|
*c='\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit_branch(const char* buf) {
|
||||||
|
if(strcmp(buf, EXIT_CMD)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
return; // just for gcc but exit shouldn't fail
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user