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 *);
|
||||||
|
|
||||||
|
|
5
main.c
5
main.c
|
@ -1,10 +1,11 @@
|
||||||
int
|
int
|
||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
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