Thread: Need help with this segmentation fault that is driving me nuts.

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

    Red face Need help with this segmentation fault that is driving me nuts.

    This post is related to another post, but instead of editing the post, i decided to ask the same question in a different way.
    If you do consider this as reposting, i am really sorry.

    IMPORTANT:-
    *I have decided to write out the problems , instead of posting a hundred line post containing 80 lines of C code.
    *The contents in the detail tags are additional information that might be of some help.


    I have a structure named as node structure is
    Code:
     structure node{
      int rownum;
      char rowbuff[MAXCOL]// --MAXCOL is a sybolic definition that is used to indicate, in this                         
                                         //--  context the length of the string
      struct node *nextrow;
     }

    <detail>
    This structure used to store the data in each row in my text editor;
    There is another pointer to the target row being manipulated upon named "temp"
    </detail>
    **I am passing this structure to a function using pass by reference, i.e a pointer to the structure. **
    How do i access base address of "rowbuff" so that i can copy another string (which *will not* overflow rowbuff )
    named "tempbuff" so that i can copy the contents of "tempbuf" to "rowbuff" using strcpy function call.
    How do i access the next row (not the address of the next row, but the next row).

    <QUESTIONS>
    1) In the structure definition can i initialize every "nextrow" pointer to null.
    2) How do i make "temp" at the end of this function to point to the next row structure.
    </QUESTION>

    <detail>
    Detail regarding question 2
    I might use another global pointer to point to the next structure at the end of this function .
    </detail>
    See this post for some incomplete information
    Last edited by progue; 10-27-2007 at 01:34 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could write a simple linked list implementation for us, which doesn't use any messy global variables.

    Then we can tell you where you've messed up in your understanding of the problem.

    It's not like you're the first person to ask about "how do I write a linked list".

    > How do i access base address of "rowbuff" so that i can copy another string
    Where you had var.rowbuff, now you have p->rowbuff
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 05:50 PM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM