redid structure for 334 keeping things clean now
This commit is contained in:
parent
6e9ef2f3d2
commit
bc5affc51b
11
334/Makefile
11
334/Makefile
@ -1,3 +1,10 @@
|
||||
# Single make file for everything becauz lazy
|
||||
1:
|
||||
gcc bindec.c -o bin
|
||||
object=hw.c
|
||||
cc=gcc
|
||||
output=bin
|
||||
|
||||
default:
|
||||
$(cc) $(object) -o $(output)
|
||||
|
||||
clean:
|
||||
rm -f $(output)
|
||||
|
44
334/homework/2/msh.c
Normal file
44
334/homework/2/msh.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PROMPT "msh> "
|
||||
#define EXIT_CMD "exit"
|
||||
// Accounting for the \n
|
||||
#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
|
||||
}
|
22
334/homework/2/processes.txt
Normal file
22
334/homework/2/processes.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# Instructions: edit this file to provide your homework answers.
|
||||
#
|
||||
# Problem numbers are shown on lines that begin with #@.
|
||||
# Please put your solution to a problem on the line *after* the
|
||||
# line with the problem number.
|
||||
#
|
||||
# Do not modify this file *except* to add lines as needed after each problem.
|
||||
# Blank lines are ignored. You don't need to put your name in the file.
|
||||
#
|
||||
# No points will be awarded to incorrectly-formatted files.
|
||||
#
|
||||
|
||||
#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer)
|
||||
b
|
||||
#@ 2 -- enter 'a', 'b', or 'c'
|
||||
c
|
||||
#@ 3 -- enter 'a' or 'b'
|
||||
b
|
||||
#@ 4 -- enter 'a' or 'b'
|
||||
b
|
||||
#@ 5 -- enter 'a', 'b', or 'c'
|
||||
c
|
32
334/homework/2/puzzle.txt
Normal file
32
334/homework/2/puzzle.txt
Normal file
@ -0,0 +1,32 @@
|
||||
# Instructions: edit this file to provide your homework answers.
|
||||
#
|
||||
# Problem numbers are shown on lines that begin with #@.
|
||||
# Please put your solution to a problem on the line *after* the
|
||||
# line with the problem number.
|
||||
#
|
||||
# Do not modify this file *except* to add lines as needed after each problem.
|
||||
# Blank lines are ignored. You don't need to put your name in the file.
|
||||
#
|
||||
# No points will be awarded to incorrectly-formatted files.
|
||||
#
|
||||
|
||||
#@ 1 -- enter a single number
|
||||
1
|
||||
#@ 2 -- enter 'Y' or 'N'
|
||||
2
|
||||
#@ 3 -- enter 'Y' or 'N'
|
||||
Y
|
||||
#@ 4 -- enter 'Y' or 'N'
|
||||
N
|
||||
#@ 5 -- enter text on a single line
|
||||
some stuff
|
||||
#@ 6 -- enter 'Y' or 'N'
|
||||
Y
|
||||
#@ 7 -- enter text on a single line
|
||||
stuff
|
||||
#@ 8 -- enter 'Y' or 'N'
|
||||
N
|
||||
#@ 9 -- enter text on a single line
|
||||
some stuff
|
||||
#@ 10 -- enter 'Y' or 'N'
|
||||
Y
|
Loading…
Reference in New Issue
Block a user