Thread: Problems with scanf

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    Problems with scanf

    I'm making a shell(look at code), but when I enter a command
    like "dir /p", the program treats it like to commands: "dir" and "/p". Can I do anything to change this?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char path[64] = "C:\\Dev-C++>"; char input[10];
        
    for(;;)
        {
               printf("%s",path);
               scanf("%s",&input);
               system(input);
        }
        return 0;
    }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    fgets( ) to get a line of input.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Calculating
    By danepporambo in forum C Programming
    Replies: 6
    Last Post: 04-25-2006, 01:04 AM
  2. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  3. scanf to struct pointer
    By ronenk in forum C Programming
    Replies: 11
    Last Post: 12-20-2004, 10:22 AM
  4. First scanf() skips next scanf() !
    By grahampatten in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:47 AM