Find the answer to your Linux question:
Results 1 to 3 of 3
my program is: Code: #include <stdio.h> int main(void) { int max_item; printf("please input number"); scanf("%d", &max_item); int array[] = max_item; scanf("%lf", array[0]; printf("%lf", array[0]) getch(); } help i dont know ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    1

    Program help needed

    my program is:
    Code:
    #include <stdio.h>
    int main(void)
    {
    
    int max_item;
    
    printf("please input number");
    scanf("&#37;d", &max_item);
    
    int array[] = max_item;
    
    scanf("%lf", array[0];
    printf("%lf", array[0])
    getch();
    }
    help i dont know about it really,. all i want to do is to make a program that can accept inputs using an array., thankyou., hope to hear from you soon..
    Last edited by devils casper; 01-06-2008 at 10:09 AM. Reason: added [code].....[/code] tag.

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    I've moved this to its own thread. Please post new threads for new problems to allow it to be addressed properly.

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    1. You have syntax errors in your code. I know this isn't in the rules, but normally you can show great courtesy by cleaning them up before posting the code. That's because we're unpaid volunteers, and it's nice for us not to have to do that for you when we want to experiment with your code by compiling it ourselves and modifying it as necessary.

      Of course, that doesn't apply if you have a question about why you got a syntax error.
    2. In particular, you have declared two data items (of different types) called max_item. Any particular reason to call them both the same name? It won't work.
    3. Don't use scanf(). I explain why here. Instead, use fgets() to read a line of input at a time, and use sscanf() to parse that line into your variables.

      Of course, at this point someone might show how C++ has even better ways to do the input, but that wasn't your question. :)
    4. What's that getch() doing in there?
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...