A quick array question

This is a discussion on A quick array question within the C Programming forums, part of the General Programming Boards category; Hello All, I am learing C and was trying to find the attributes of an array (length, range...etc) I have ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    26

    Question A quick array question

    Hello All,

    I am learing C and was trying to find the attributes of an array (length, range...etc)

    I have the main function taking in an array like so...

    int main(int argc, char *argv[])
    {
    Code....

    but i don't know how to pass in an array to check if the code i wrote works properly. Do i do it in the terminal after the C file is compiled? If so, how?

    Any help would be much appreciated,

    Thanks -Nick

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Consult the FAQ entry.


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

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    26
    Cheers Quzah

    Had trouble searching up the problem with my limited knowledge of terminology.

    -Nick

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    26
    sigh, ok i still dont get it. This is a function to find the range of values in an array of integers...it is someone elses code that i am using to teach myself about arrays.

    Code:
    #include <stdio.h>
    #define MAX 100
    
    int spread(int b[], int size);
    
    int main(int argc, char *argv[])
    {
       int n;
       int count = 0;
       int a[MAX];
    
       while (count < MAX && scanf("%d", &n) != EOF)
       {
       a[count++] = n;
       }
       printf("spread was %d\n", spread(a, count));
       return 0;
    }
    
    int spread(int b[], int size)
    {
       int lo, hi, i;
    
       if (size == 0)
       return 0;
       lo = hi = b[0];
       for (i = 0; i < size; i++)
       {
          if (b[i] > hi)
          hi = b[i];
          if (b[i] < lo)
          lo = b[i];
       }
       return (hi - lo);
    }
    I compile this as: gcc array.c -Wall -o array
    Then run it: ./array (i figure numbers go here but that didn't work)
    What do i do to input the array of integers?

    Thanks -Nick

    [or maybe the code i am using is wrong...]
    Last edited by Rad_Turnip; 03-30-2006 at 04:00 AM.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    26
    Ok i get it now, have tested what the FAQ say on some really short code i made. Its the code that i was playing with (listed above) that is somehow wrong.

    -Nick
    Last edited by Rad_Turnip; 03-30-2006 at 04:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embaracing Array question
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 04-06-2009, 11:29 AM
  2. Quick Question: 2D Array with char **
    By Phoenix_Rebirth in forum C Programming
    Replies: 4
    Last Post: 01-29-2009, 07:33 AM
  3. Quick question about types...
    By Elysia in forum C++ Programming
    Replies: 32
    Last Post: 12-07-2008, 05:39 AM
  4. Memory Address of Array Question
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 10:58 AM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM

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