[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Quick C problem



> strcpy(newStr,strtok(tmpString,"<"));
> strcpy(tmpString,newStr);
> strncpy(newStr,tmpString,*strchr(tmpString,'>') - 2);
> 
> I know its wrong, and I'll get flamed for it.... its the last line that
> doesn't work.

  strncpy(newStr,tmpString,strchr(tmpString,'>')-tmpStr);

Though I would do it in one strcpy -

char* b=strchr(tmpStr,'<');
char* e=strchr(b,'>');
if(b!=NULL && e!=NULL){
  strncpy(newStr,b+1,(e-b)-1);
}

Alex Y.
-- 
   _ 
 _( )_
(     (o___           +-------------------------------------------+
 |      _ 7           |            Alexander Yukhimets            |
  \    (")            |       http://pages.nyu.edu/~aqy6633/      |
  /     \ \           +-------------------------------------------+


Reply to: