fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. int main(void) {
  6. // your code goes here
  7. int w, h, i, j;
  8. char buffer[100];
  9. scanf("%d %d", &w, &h);
  10. int num[w][h];
  11. gets(buffer);
  12. for(i=0; i<h; i++)
  13. {
  14. gets(buffer);
  15. char *token = strtok(buffer, " ");
  16. for(j =w; j && token; j--)
  17. {
  18. num[i][w-j] = atoi(token);
  19. token = strtok(NULL, " ");
  20. }
  21. if(j)
  22. {
  23. //Do what you wish to do on error
  24. printf("\nError!!! %d inputs are missing\n", j);
  25. }
  26. }
  27. for(int i=0; i<h; i++)
  28. {
  29. for(int j =0; j<w; j++)
  30. printf("%d ", num[i][j]);
  31. printf("\n");
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4484KB
stdin
6 4
0 1 2 2 1 0
1 0 0 0 0 
1 0 0 0 0 1
0 1 1 1 1 0
stdout
Error!!! 1 inputs are missing
0 1 2 2 1 0 
1 0 0 0 1 0 
1 0 0 0 0 1 
0 1 1 1 1 0