Thread: Structure related query

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

    Structure related query

    Hi,
    I want to access an array within a structure which is passed to a function. I am getting series of segmenatation fault errors. I tried manipulating the expression and the exrpession goes something like this
    Code:
    #include "interface.h"
    extern char TBUFF[MAXCOL];
    extern nodez *head;
    extern nodez *last;
    void processfile(FILE *fp)
    {
    return;
    }
    void savetobuffer()
    {
     int i;
     CREATENODE(local); //MACRO 
     local=last;
     if(last==NULL) //In other words the first node is being inserted
     allocrowa(head);
     else
     allocrowb(local);//Dont wory about the above part *****PLEASE*****
     for(i=0;i<MAXCOL;i++)
     {
     char *temp0;
     temp0=(last->content); 
     (*(temp0+i))=TBUFF[i];//Here i cant use strcpy and cant use this for loop too.
     //local->content[i]="\n";
     }
    }
    Thanks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    What are you expecting us to "magic" up for you, based on the partial information you've provided.

    A short complete program which seg-faults, and which we can read / analyse / try for ourselves is what is needed to accurately say why it crashes.

    Otherwise, there's simply too many ways to mess up.
    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.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You've given very little for anyone to work on. What does a nodez struct look like? What does CREATENODE do? What does allocrowa/allocrowb do? What has been done with last prior to calling the function when you get the segfault? If I had to guess at this point, I'd say that whatever last->content is supposed to be it isn't pointing to a valid memory address.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Replies: 1
    Last Post: 09-18-2005, 09:06 PM
  3. Query related to DisconnectEx?
    By dp_76 in forum Networking/Device Communication
    Replies: 5
    Last Post: 05-25-2005, 02:33 AM
  4. Query related to recv()?
    By dp_76 in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-16-2005, 07:25 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM