#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    Post Getting user inputs in C programming


    I am new to C and I have followed Java before.I study C for my future studies.The problem i get is I cannot input user inputs to an array and print it :( .This is my code:-

    #include <stdio.h>

    int main(void)
    {
    int arr[3];
    int i,j;

    for(j=0; j<3; j++){
    scanf("%d\n", arr[j]);
    }

    for(i = 0; i < 3 ;i++)
    printf("%d\n",arr[i]);


    return 0;
    }

    can some one help me to correct this please!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    1. Please use [code][/code] when posting code.

    2. scanf("%d\n", arr[j]);
    scanf needs a pointer to store each converted result.
    So
    scanf("%d\n", &arr[j]);
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by salem
    1. Please use [code][/code] when posting code.

    2. scanf("%d\n", arr[j]);
    scanf needs a pointer to store each converted result.
    So
    scanf("%d\n", &arr[j]);
    Thnks for ur answer..I got it..
    And i say you I am not an indian:(
    Is that the way u get ur marks for xm(writing 4n number on ur xm paper ??)
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    It's a signature link, not aimed at you specifically.

    It's just for anyone who thinks they can somehow scam their way through an education by either cheating or corruption.
    We get a lot of "please do it for me" posts on forums, and the link is a useful reminder for those kinds of people.
    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by salem
    It's a signature link, not aimed at you specifically.

    It's just for anyone who thinks they can somehow scam their way through an education by either cheating or corruption.
    We get a lot of "please do it for me" posts on forums, and the link is a useful reminder for those kinds of people.
    you may be a genius man at computing. you have registered here in 2005.that means you are at least 7 years experienced.As an experienced man do not look at each and every man as cheaters. Think of your early days..You too may have these kind of problems which are little but gives biginer huge headaches.

    personally, I am a computer science student currently i am on a vacation after completing first year studies..I studied Java in fist year as a introduction to programming.I have to study the module operating systems in my second year.So i thought to have a knowledge of C language as OS module based on it.

    I do not know from where you are.But I have heard of people(mostly from Europe.)who put their assignments on sites(such as Fiverr) and get them completed for money..Mind you,,Lot of Indians work on that sites and do others work for money..(I am not an Indian)..

    There are cheaters everywhere..But not all

IMN logo majestic logo threadwatch logo seochat tools logo