fork(1) download
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7. const char* texts[] = { "foo=54", "foo=7h", "rubbish", NULL };
  8. int pos, foo, i;
  9. for (i = 0; texts[i]; i++)
  10. {
  11. printf("Is %s valid ? ", texts[i]);
  12. if (sscanf(texts[i], "foo=%d%n", &foo, &pos) == 1 &&
  13. pos == strlen(texts[i]))
  14. {
  15. printf("yes\n");
  16. }
  17. else
  18. {
  19. printf("no\n");
  20. }
  21. }
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
Is foo=54 valid ? yes
Is foo=7h valid ? no
Is rubbish valid ? no