fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. #define BUFFSIZE 100
  5. char buf[100] = { '\0' };
  6. char resbufI[6] = { '\0' };
  7. char resbufII[11] = { '\0' };
  8. char resbufIII[11] = { '\0' };
  9. char str[] = "01234 0123456789 01234";
  10.  
  11. sprintf(buf, "%%5s %%%ds %%%ds", BUFFSIZE / 10, BUFFSIZE / 10);
  12.  
  13. printf("buf: \"%s\"", buf);
  14.  
  15. /* Use buf = "%5s %10s %10s" */
  16. sscanf (str, buf, resbufI, resbufII, resbufIII);
  17.  
  18. printf("\nresbufI: \"%s\""
  19. "\nresbufII: \"%s\""
  20. "\nresbufIII: \"%s\"",
  21. resbufI,
  22. resbufII,
  23. resbufIII);
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
buf: "%5s %10s %10s"
resbufI:   "01234"
resbufII:  "0123456789"
resbufIII: "01234"