Thread: Regex or scanf()?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    5

    Regex or scanf()?

    Hi, I'm making a console-based connect four game as a beginner project, I want have the user input a command in this syntax, "drop <int column_number>" to drop a coin. The problem is how! I want to be able to seperate the number from the command a store it into a seperate variable - and if the syntax is not as expect, I do not want the program to crash, I want it to just ask again.

    I have tried something like below, which kind of works and then crashes straight after. My understanding of scanf() is limited because I do not have the MSDN library.
    PHP Code:
    int col;
    scanf("drop %d", &col);
    return 
    col-1
    My understanding is that where %d is, is the value that will be put into col - please correct me if I am wrong.
    Last edited by Avochelm; 05-08-2004 at 11:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM