commands take buf, bad commmands dont segfault
parent
5340cd4ef2
commit
39ab7a9055
|
@ -1,3 +1,3 @@
|
||||||
void (*commands[256])() = {
|
void (*commands[256])(char *) = {
|
||||||
NULL,
|
NULL,
|
||||||
['q'] = c_quit,
|
['q'] = c_quit,
|
||||||
|
|
7
efn.h
7
efn.h
|
@ -1,4 +1,7 @@
|
||||||
extern void (*commands[256])();
|
#include <stdlib.h>
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
void c_quit();
|
extern void (*commands[256])(char *);
|
||||||
|
|
||||||
|
void c_quit(char *);
|
||||||
|
|
||||||
|
|
3
main.c
3
main.c
|
@ -4,7 +4,8 @@ main(int argc, char **argv) {
|
||||||
while(1) {
|
while(1) {
|
||||||
char *com = fgets(buf, sizeof(buf), stdin);
|
char *com = fgets(buf, sizeof(buf), stdin);
|
||||||
if (com != NULL) {
|
if (com != NULL) {
|
||||||
commands[com[0]]();
|
if (commands[com[0]] != NULL) commands[com[0]](buf);
|
||||||
|
else puts("invalid command.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue