Advertisement
Guest User

Untitled

a guest
Feb 15th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1.  
  2. char *StripCarriageReturns ( const char *thestring )
  3. {
  4.  
  5. UplinkAssert (thestring);
  6.  
  7. // Is there a cr?
  8.  
  9. char *firstcr = strchr ( thestring, '\n' );
  10.  
  11. if ( !firstcr ) {
  12.  
  13. // No cr found - copy string and return it
  14.  
  15. char *result = new char [strlen(thestring)+1];
  16. strcpy ( result, thestring );
  17. return result;
  18.  
  19. }
  20. else {
  21.  
  22. // Found a cr - so shorten string to that point
  23.  
  24. int newlength = firstcr - thestring;
  25. char *result = new char [newlength+1];
  26. strncpy ( result, thestring, newlength );
  27. result [newlength] = '\x0';
  28. return result;
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement