difficulty in displaying array contents

This is a discussion on difficulty in displaying array contents within the C Programming forums, part of the General Programming Boards category; Why this code doesn't print array contents? Code: #include<stdio.h> Code: #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    50

    difficulty in displaying array contents

    Why this code doesn't print array contents?

    Code:
    #include<stdio.h>
    Code:
    #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
    int array[] = {23,34,12,17,204,99,16};
    
    int main()
    {
    int d;
    
    for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
    printf("%d\n",array[d+1]);
    
    return 0;
    }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Run this code
    Code:
    #include <stdio.h>
    
    int main(void)
    {
         long unsigned int lUi = 7;
    
         int i = -1;
    
         if(i < lUi)
            printf("ok\n");
         else
            printf("not ok\n");
    
         return 0;
    }
    see the output.

    Try to see why it is relevant with your problem

    Ok a little help -> click me

    If you know how a number is stored inside your computer you are ok
    Last edited by std10093; 11-27-2012 at 07:59 AM.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    try
    Code:
    for(d=-1;d <= ((int)TOTAL_ELEMENTS-2);d++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  2. displaying the contents of an html file in a table
    By confuted in forum Tech Board
    Replies: 3
    Last Post: 08-02-2003, 07:50 PM
  3. displaying stack contents
    By threahdead in forum Linux Programming
    Replies: 3
    Last Post: 05-23-2003, 11:15 AM
  4. Displaying disk contents in window
    By HisWord in forum Windows Programming
    Replies: 6
    Last Post: 08-15-2002, 08:31 PM
  5. displaying contents of a text file
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-26-2002, 01:05 PM

Tags for this Thread


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