[OCLUG-devel] strcpy segmentation faults
    Doug Jolley 
    ddjolley at gmail.com
       
    Tue Jun 21 10:14:55 PDT 2005
    
    
  
Hi.  I'm very green but I'm really trying to learn C.  I seem to keep
coming up with segmentation fault errors and they always seem to occur
within the context of a strcpy.  I am appending an example function I
wrote that is intended to remove the beginning part of a string up to
the first occurrence of an underscore (_).  I'm getting a segmentation
fault and the strcpy seems to be the culprit.  I am having similar
problems elsewhere.  Aside from wanting to know what my specific
problem is in this case, I'm wondering what is the best procedure for
trouble shooting segmentation faults.  Thanks for any input.  Here is
the example:
 char *trim(char *p2c)
 {
  char *ptr1;
  /* If p2c contains an '_', trash it and any characters that prceed it. */
  ptr1=strstr(p2c,"_");
  if (ptr1!=NULL)
    strcpy(p2c,ptr1+1);
  return p2c;
 }
     ... doug
-- 
(Not digitally signed.)
    
    
More information about the OCLUG-devel
mailing list