fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main ()
  6. {
  7.  
  8. char *first,*second,*start;
  9. const char *str = "Sept 10 2012; undefined SPAM (uid AUIZ); 03_23_1 user FOO 2012_2";
  10. char *find = "SPAM";
  11.  
  12. first = strstr(str, find);
  13. char res[15]={'\0'};
  14. if (first != NULL)
  15. {
  16. start=second = first;
  17. while(*second != '\0')
  18. {
  19. if (isdigit(*second))
  20. {
  21. start =second;
  22. while(*second != '\0')
  23. if(*second=='_' || isdigit(*second) )
  24. second++;
  25. else
  26. break;
  27.  
  28. break;
  29. }
  30. second++;
  31. start++;
  32. }
  33. }
  34.  
  35. strncpy ( res, start, second-start );
  36. res[second-start] = '\0';
  37. printf("%s %s\n",find,res);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
SPAM  03_23_1