fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char str[] = "0,228,03,1771,2d6f,55,62";
  8.  
  9. const uint8_t MAX_TOKENS = 7;
  10. uint8_t tokenCounter = 0;
  11. char *tokens[MAX_TOKENS];
  12.  
  13. char *ptr = strtok( str, "," );
  14. while ( ptr != NULL && tokenCounter < MAX_TOKENS )
  15. {
  16. tokens[ tokenCounter++ ] = ptr;
  17. ptr = strtok( NULL, "," );
  18. }
  19.  
  20. int32_t
  21. mnc = atoi( tokens[2]),
  22. mcc = atoi( tokens[1]),
  23. lac = strtol( tokens[3], NULL, 16),
  24. cellid = strtol( tokens[4], NULL, 16);
  25.  
  26. printf( "%d %d %d %d\n", mnc, mcc, lac, cellid );
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
3 228 6001 11631