Thread: I wonder...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    12

    Unhappy I wonder...

    I need your help in my practice with C programming. I am new at it, and am trying to get bettaer at it since I really enjogy it a lot.
    How do I go along doing simple entering words in a adynamically allocated array? and how Do I keep expanding it until all memory is used for example?
    Also, If I want to search a certain word inside this array, using the bsearch() finction how do I do it (case doesn't matter, i.e. independent..)?

    Thank you so much!!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: I wonder...

    Originally posted by HOWY
    I need your help in my practice with C programming. I am new at it, and am trying to get bettaer at it since I really enjogy it a lot.
    How do I go along doing simple entering words in a adynamically allocated array? and how Do I keep expanding it until all memory is used for example?
    Also, If I want to search a certain word inside this array, using the bsearch() finction how do I do it (case doesn't matter, i.e. independent..)?
    So many questions........ and all I'm going to say is pick section, and try writing it. Use this board and google to help you along the way, and post code here when you have trouble with it.

    Have fun..
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >how Do I keep expanding it until all memory is used for example?
    Something along the lines of this:
    Code:
    #define HAHA 1
    static void killMe ( char *stg, unsigned long size )
    {
      while ( HAHA ) {
        stg = realloc ( stg, size );
        printf ( "%d\n", size );
        size *= 2;
      }
    }
    Though how well it will work depends on how stupid your operating system is.

    >How do I go along doing simple entering words in a adynamically allocated array?
    How do you enter words into a static array? Same principle.

    >using the bsearch() finction how do I do it
    Look up qsort and bsearch, then read up on how they are used.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed