array

This is a discussion on array within the Windows Programming forums, part of the Platform Specific Boards category; sup all... im tring to creat a simple shell program.. and someone told me that i need to add some ...

  1. #1
    Unregistered
    Guest

    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..

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Unregistered
    Guest
    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

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21