fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. void replace_callID ( char* msg, char* newVal)
  8. {
  9. const string callIdToken = "CALL-ID: ";
  10. string s(msg);
  11. string u(s);
  12. transform(u.begin(), u.end(), u.begin(), ::toupper);
  13. size_t pos, pos1;
  14. if((pos = u.find(callIdToken)) != string::npos &&
  15. (pos1 = u.find("\r\n", pos)) != string::npos)
  16. {
  17. s.replace(pos + callIdToken.length(), pos1 - pos - callIdToken.length(), newVal);
  18. strcpy(msg, s.c_str());
  19. }
  20. }
  21.  
  22. int main() {
  23. // your code goes here
  24. char msg[100];
  25. strcpy(msg, "test\r\nCall-Id: 1234\r\ntest");
  26. replace_callID (msg, "1112458254");
  27. cout << msg;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
test
Call-Id: 1112458254
test