Enter a number

This is a discussion on Enter a number within the C Programming forums, part of the General Programming Boards category; I have got a question. When a user enters a number, it will automatically be prepared to get that amount ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    21

    Enter a number

    I have got a question. When a user enters a number, it will automatically be prepared to get that amount of variables.

    Exp:

    Enter numbers to process:3

    Enter number:1.2
    Enter number:17
    Enter number:12

    thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    So you read a value into say n

    Then do
    for ( i = 0 ; i < n ; i++ )
    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.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    You also have to allocate some memory for vars:
    Code:
    #include <stdlib.h>
    // Some crap
    int n, i;
    double *dTbl;
    
    scanf("%d", &n);
    dTbl = malloc(n*sizeof(*dTbl));
    for (i = 0; i < n; i++)
        scanf("%f", dTbl[i]);
    
    // TODO: Do something with your numbers
    
    free(dTbl); // Remember to free allocated memory

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-08-2009, 08:26 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Assignment output help
    By Taka in forum C Programming
    Replies: 13
    Last Post: 09-23-2006, 11:40 PM
  4. endless loop for scanf - plz help
    By owi_just in forum C Programming
    Replies: 18
    Last Post: 03-20-2005, 12:41 PM
  5. Replies: 3
    Last Post: 03-04-2005, 01:46 PM

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