Ignoring timestamps

0

I am trying to write some code which ignores the timestamps of the strings and reads the rest of the strings of varying lengths e.g.

14/07/20 18:27:02:533 ... C: SPLT 0x00 MTE_DL_RBSFN_STAT 0X00000001 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000 0X00000000
14/07/20 18:27:02:533 ... SLOF
14/07/20 18:27:02:537 ... C: SLOF 0x00
14/07/20 18:27:02:541 forg l1 SetPortMapping 0
14/07/20 18:27:02:550 C: FORG 0x00 Ok l SetPortMapping 0

I am trying to use sscanf function to ignore the stamps and read rest of the string. This will happen in a loop. So I can not use defined %s and %*s. I need an algorithm to ignore part of the string i.e timestamps and read the remaining string. Thanks

c++
scanf
asked on Stack Overflow Aug 1, 2020 by Param • edited Aug 1, 2020 by Galik

1 Answer

0

You've noted that the timestamps aren't of fixed length. However, if it's always the case that the format is date timestamp the...rest..., then you could get the line as a string, then use string.find (twice) to find the second spacebar, e.g.

std::string s;
while (getline(input, s)) {
   size_t loc = s.find(' ');
   loc = s.find(' ', loc + 1);
   s = s.substr(loc + 1);
}
answered on Stack Overflow Aug 1, 2020 by Oantby

User contributions licensed under CC BY-SA 3.0