Thread: Arrays question

  1. #16
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by tlovaj View Post
    New to C, so I'm kind of confused about how C works when it comes to arrays. If I'm given an array with n number of chars in it. How would I go about finding the size of the array, and then grabbing the last char of the array. I was told that C does not put a "null" at the end of an array so one could go on and on before actually finding a "\0" so I was wondering how I might do so using a for loop.

    Thanks.
    Try this and let us know if it works.

    Code:
    printf("\nArray size %d",n);
    Then if the array is called "arr"


    Code:
    
    printf("\nArray last characrer value %c",arr[n-1]);
    Last edited by esbo; 02-12-2008 at 05:59 PM.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What is that supposed to do and what is "n"?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    What is that supposed to do and what is "n"?
    "n" is the number of character in the array

    "If I'm given an array with n number of chars in it."

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That assumes that the size is passed in the first place. Just because it's an array of n elements doesn't mean the information exists within the function.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    7
    sweet thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 05:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 02:40 PM