keeping values of scanf

This is a discussion on keeping values of scanf within the C Programming forums, part of the General Programming Boards category; i was wondering if it is possible to have a scanf in a for loop and keep each value the ...

  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
    32,821
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08: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, 07: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

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