Thread: keeping values of scanf

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    19

    Question keeping values of scanf

    i was wondering if it is possible to have a scanf in a for loop and keep each value the user inputs? how can i store each value the user inputs?
    i need to keep each value because the program takes input from the user and takes the derivative of the polynomial. now i am using a for loop but i don't know how to keep each value for the scanf. am i approaching this the wrong way? what can i do? here is the part of the code. (it repeats for as many values of "a" there is).
    Code:
     
    for(b = 0; b <= a; b++)
        {
        printf("Enter coefficient for x^%d: ", b);
        scanf("%d", &c);
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Make c an array

    Then
    Code:
    scanf( "%d", &c[b] );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. keeping track of values
    By marquis1431 in forum C Programming
    Replies: 3
    Last Post: 04-09-2008, 07:52 PM
  2. Sending values to a control
    By Zyk0tiK in forum C Programming
    Replies: 6
    Last Post: 12-02-2005, 06:29 PM
  3. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  4. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 07:16 PM
  5. How to read in empty values into array from input file
    By wpr101 in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:59 PM