Thread: need help with some input

  1. #1
    Registered User
    Join Date
    Oct 2002

    need help with some input

    ok i need to input numbers for this program i am working on i dont need help with the code for the rest i just need to know how i can input numbers, in a certain way the description asks, and then stop inputing once a certain value is inputted. Here's a description of the program:

    2 Project description 
    The input to your program is to consist of a sequence of input lines (redirected from an ASCII text file using standard UNIX input redirection). Each line will contain 4 integers. These will be: 
    shape code - The possible shape codes are: 
    1 for triangle 
    2 for diamond 
    3 for parallelogram 
    4 for trapezoid 
    base size for the shape 
    height for the shape 
    rotation in number of degrees (clockwise) to rotate the shape before drawing it 
    There are some restrictions on the values which may be used. They are listed under "Error Checking" below. 
    As an example, suppose the program receives the following line of input: 
    3 11 8 0
    This instruction says: ``Draw shape code 3 (parallelogram), sized so that it is 11 wide by 8 high, and rotate the shape 0 degrees before drawing it. (This is the command which could be used to draw the parallelogram shown above.) 
    The last line in the input will always contain a shape code of -1; it may or may not contain other data items. This is the signal that the program should terminate. (Do not try to draw anything or print any error messages when this line is processed.)
    so if anyone can help, please do, thanks!, basically i just need to know how to continue to input values, until the user inputs a -1. thanks

  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    You can use fgets(), fscanf() or some other file-reading function to read from the file and keep a counter to know how many integers must still be read before a line is completed. Or you could just read in a whole line and analyse that line.

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    you could use an array to hold your four numbers as you read in the values

    file loop
    temp holder
    array[index++] = temp holder

    when your array is filled process the drawing function, then repeat for the next shape.

    array[0] has the shape
    array[1] has the width
    array[2] has the height
    array[3] has the rotation

    you can also use temp holder to validate that the input is good prior to using it.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem grabbing k/b input
    By falcon9 in forum C Programming
    Replies: 2
    Last Post: 10-28-2007, 11:47 AM
  2. continues input
    By Matty_Alan in forum C Programming
    Replies: 2
    Last Post: 06-22-2007, 10:04 PM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  4. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  5. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 01:50 PM