#I'm making a simple command prompt in C, is there a better way to make it?

1 messages · Page 1 of 1 (latest)

faint juniper
#

I'm a newbie so sorry in advance

When you enter "q", it quits. But I want to know how I can make it work better

silver pawn
#

Switch case 0: makes little sense

#

Just do if(strcmp(u_input, "q") == 0) {} else {}

#

gets(u_input); is unsafe

#

I would recommend not using globals

#

This can be cleaner if you pass an input string to a handle command function

faint juniper
#

I don't want the classic elseif ladder

silver pawn
#

you can either make an if-else ladder (which imo is perfectly fine), or you can make a hash table of command names and function pointers (if you don't have many keys an array of pairs can be fine too)

bitter marten
faint juniper
bitter marten
#

If it does then you'd throw and error and bail out