Thread: Enter a number

  1. #1
    Registered User
    Join Date
    Aug 2004

    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.


    Enter numbers to process:3

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


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

  3. #3
    Registered User
    Join Date
    Jun 2004
    You also have to allocate some memory for vars:
    #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, 09: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, 01:41 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM