Thread: about Array problem pls help

  1. #1
    Unregistered
    Guest

    about Array problem pls help

    I am new with C and I have some problems with my source code.

    This program is about the EAN (European Article Number) system. The user
    will have to enter a code number with 12 digits, like this:
    "Enter the numbers :"
    User types: "987654321123" then enter
    The question is how can I use the above digits separately, I mean save as an
    array with each single digit as an element, so 9 goes to array 0, 8 goes to
    array 1, 7 goes to array 2, and so on.
    After that I can calculate them such as (array1*array3)/array 2
    Thanks in advance

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > I am new with C and I have some problems with my source
    > code.

    The main problem with your source code seems to be that you don't have any. How about you:

    1) Post your source code using the correct code tags.

    2) Post the EXACT problem and/or error messages you are encountering. We are not mind readers.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Unregistered
    Guest
    this is my code i just start it
    when i enter itemcode: 987654321123
    and i tried to check the value of Array[2] it should be 8
    but it didn't show up

    #include<stdio.h>
    #include<stdlib.h>

    int main(void)
    {
    char input[13];
    int i,itemcode[13];

    puts("Enter itemcode:");
    gets(input);
    for(i=0;i<13;i++){
    itemcode[i] = atoi(input[i]);
    printf(itemcode[2]);

    }

    return 0;
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Two huge problems:

    puts("Enter itemcode:");
    gets(input);

    1) Never ever use 'gets'.

    for(i=0;i<13;i++){
    itemcode[i] = atoi(input[i]);
    printf(itemcode[2]);

    2) Learn how to use printf correctly. Your usage is wrong. Just plain wrong.

    printf( "%d", itemcode[2] );

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  4. problem: reading user input into an array
    By alpha561 in forum C Programming
    Replies: 13
    Last Post: 05-24-2002, 07:23 PM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM