Results 1 to 3 of 3

Thread: Array functions

  1. #1

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448

    Array functions

    I'm using C... not C++. I need to know some of the basics about arrays. Fortunitly I already know how to declare, set, and use arrays but there is more I learned in other languages that I want to learn here. How do I return the number of items in an array, get the last item in an array (not using indexs to get it... using something like perl's "pop(@bleh)" function which returns the last item), how to add an item to the end of an array, etc. Any good array functions are welcome. Also, any tutorials about file handling would also be welcome. As you can guess, most tutorials only touch the basics of how to do each thing... I want to dig deeper. Thanks in advance!

    -zer0 flaw

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    None of what your requested -
    array length
    dynamic array insert
    etc.

    is available as a single library function in C. It is much more low-level than VB. You have to roll your own.

    dynamic arrays require using malloc & realloc & pointers
    Use sizeof() to find array length.

    Most C programmers have a library of routines they lug around from place to place. Or know a site to download them from.

  3. #3

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448
    I'm curious if this would work... all I want to do is add an item to the end of an array:

    bleh = ("abc", "123", 13);
    bleh = (bleh, "heh");
    /* bleh now =s ("abc", "123", 13, "heh") */

    If that doesn't work how do I go about this? Also, printing an array... besides looping through each item and printing the item each time, is there a quicker way (ex: printf("bleh") will print each item seperated by a space in perl).

    Lastly, how do I get the 3rd, 4th, and 5th characters in a string? Other languages can do this... not sure about C. Sorry for the dumb newbie questions but I've read numerous tutorials on C now and still have much info to be obtained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width