Character pointer arrays

This is a discussion on Character pointer arrays within the C Programming forums, part of the General Programming Boards category; Code: I am tryin to store strings in an array **ro in vain.... any idea why it gives a compile ...

  1. #1
    axe
    axe is offline
    Registered User
    Join Date
    Jan 2006
    Posts
    33

    Character pointer arrays

    Code:
    I am tryin to store strings in an array **ro in vain.... any idea why it gives a compile time error..
    
       char **ro;
       while(fgets(c,sizeof(c),fq)!=NULL)
       {
        *ro=c;
          ro++;
       }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This is a very closely related problem to your previous question. Did you read my reply, and if so, did you understand it?

    [Actually, I don't really see why you should get a compile-time error, but I can see how it would definitely crash instantly when you get there at runtime].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    axe
    axe is offline
    Registered User
    Join Date
    Jan 2006
    Posts
    33
    Code:
    yes... i did look at the first one and i had a problem applying strcpy thatz why i tried alil different one...  it compiled but when i try to print in a separate loop, it prints only the last string.... meaning it replacing a string for a string... need some help in that...
    
       while(fgets(c,sizeof(c),fq)!=NULL)
       {
        aqq[count]=c;
        count++;
       }
       char **ar=aqq;
       while(*ar){
        printf("new %s",*ar);
        ar++;
       }

  4. #4
    axe
    axe is offline
    Registered User
    Join Date
    Jan 2006
    Posts
    33
    i also don't understand malloc
    Code:
    note

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so malloc() is a function that "gives you a piece of memory that is of a certain size" [or if it can't, you get a NULL pointer back].

    You probably need to read up on pointers a little bit. There is a tutorial at the main page , www.cprogramming.com, that explains more about pointers and dynamic memory.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335

    Angry

    STOP putting ALL your post inside code tags. It creates needlessly wide posts since all your words are strung out into one long line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. Character pointer arrays
    By axe in forum C Programming
    Replies: 1
    Last Post: 11-14-2007, 08:28 AM
  4. 2D Dynamically allocated pointer arrays
    By Lionmane in forum C Programming
    Replies: 37
    Last Post: 06-11-2005, 10:39 PM
  5. mygets
    By Dave_Sinkula in forum C Programming
    Replies: 6
    Last Post: 03-23-2003, 06:23 PM

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