(The same) segmentation error problem.

This is a discussion on (The same) segmentation error problem. within the C Programming forums, part of the General Programming Boards category; I have a structure Code: typedef struct node{ int rownum; char content[MAXCOL]; struct node *next; }nodez; and i want to ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    7

    Exclamation (The same) segmentation error problem.

    I have a structure
    Code:
      typedef struct node{
        int rownum;
        char content[MAXCOL];
        struct node *next;
       }nodez;
    and i want to copy a (global) string named TBUFF into content ( located in the structure ).
    Code:
    strcpy(last->content,TBUFF);
    Using the above line results in a segmentation error.
    Please help me.
    Thanks in advance.
    Last edited by progue; 10-31-2007 at 09:35 AM. Reason: Minor changes

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    is "last" a valid pointer?

    --
    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
    Registered User
    Join Date
    Oct 2007
    Posts
    7

    Oh... didnt think about validity of last pointer.

    If i assume that "Last" points to a valid location.
    Code:
    last->content
    Will the above statement give me the base address of the content *string*. Will the above statement do what it is supposed to do.
    Last edited by progue; 10-31-2007 at 09:57 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, there's nothing wrong with your strcpy(). Which is why I asked about "last" being valid or not.

    The other option is of course that you are copying beyond the size of your buffer, in this case more than MAXCOL bytes.

    It is probably a good idea if you post a little bit more of the code at this point, as it may be something else that is causing the problem - only that it APPEARS when you try to copy the string.

    --
    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.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    7
    No.. i better not, i have already posted partial 'C' code 2 times. Thanks a lot for the help matsp. I really appreciated the quick responce.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 06:04 PM
  2. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Replies: 7
    Last Post: 12-10-2004, 01:58 AM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 01:53 PM

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