-
array
sup all...
im tring to creat a simple shell program.. and someone told me that i need to add some arrayz..
i have posted this in the linux forum.. anywayz...
lets say if i wanted to put "ls" "cat" "pwd" and lets not forgoet "[blah@blah]$" now how can i put all of the commands in to one array so i wont have to do it this way....
Code:
vid shell(void);
char x[] = ls;
char y[] = pwd;
char z[] = cat;
void shell(void)
{
printf("[blah@blah]");
}
what is the best way for me to do this... and also what is the best way for me to keep [blah@blah]$ stay on the screen and waiting for a command to be tipe.. cause lets say if i was to type in ls i want it to show me the home dir that i am going to add... so all im asking is just for a simple code on how to work my way around this..
-
First off, for the benefit of non-native english readers, please spell properly. :)
Code:
static char *s[]={ "ls",
"pwd",
"cat"};
Now that you have them in an array use normal syntax to access the members.
-
sorry but im not that advanced in c yet.. but can you please tell me what do you mean by using normal sintax members.. or maybe show me an example.. and btw.. thanx for your reply
-
s[0] contains "ls"
s[1] contains "pwd"
s[2] contains "cat"
So use s[0], s[1], s[2] to access these strings within the array.