fork download
  1. #include <stdio.h>
  2.  
  3. struct x
  4. {
  5. char cGender;
  6. char szBirthDt[200];
  7. char szEmailAddr[200];
  8. char szFullName[200];
  9. char szStreetAddress[200];
  10. char szCity[200];
  11. char szStateCd[200];
  12. char szZipCd[200];
  13.  
  14. };
  15.  
  16.  
  17. struct y
  18. {
  19. char szFlightId[200];
  20. int iRequestSeats;
  21. };
  22.  
  23. int main(void) {
  24. struct x customer;
  25. struct y flight;
  26. int iScanfCnt;
  27. char* szInputBuffer = "m a bbbb cccccc\nsome text\nde fg hijkl mnop 10";
  28. iScanfCnt = sscanf(szInputBuffer, "%1c %1s %4s %30[^\n] %30[^\n] %2s %2s %5s %s %d\n"
  29. , &customer.cGender
  30. , customer.szBirthDt
  31. , customer.szEmailAddr
  32. , customer.szFullName
  33. , customer.szStreetAddress
  34. , customer.szCity
  35. , customer.szStateCd
  36. , customer.szZipCd
  37. , flight.szFlightId
  38. , &flight.iRequestSeats);
  39.  
  40. if (iScanfCnt < 10)
  41. {
  42. printf("invalid input when reading student data, only %d valid values. \n"
  43. , iScanfCnt);
  44. printf("\tdata is %s\n", szInputBuffer);
  45. return -1;
  46. }
  47. printf("%1c %10.2s %10.2s %30s %30s %10.2s %2s %5s %s %d\n"
  48. , customer.cGender
  49. , customer.szBirthDt
  50. , customer.szEmailAddr
  51. , customer.szFullName
  52. , customer.szStreetAddress
  53. , customer.szCity
  54. , customer.szStateCd
  55. , customer.szZipCd
  56. , flight.szFlightId
  57. , flight.iRequestSeats);
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
m          a         bb                         cccccc                      some text         de fg hijkl mnop 10