fork download
  1. #include <stdio.h>
  2. typedef struct Personal
  3. {
  4. char name[50];
  5. int ten;
  6. } Kojin;
  7.  
  8. // prototype
  9. void input(Kojin *p);
  10. void output(Kojin *p);
  11. void data_sort(Kojin *p);
  12.  
  13. int main(void)
  14. {
  15. Kojin data[5];
  16. input(data);
  17. data_sort(data);
  18. output(data);
  19. return 0;
  20. }
  21. void input(Kojin *p)
  22. {
  23. FILE *fp = fopen("data.txt", "r");
  24. for (int i = 0; i < 5; ++i, p++)
  25. fscanf(fp, "%s %d", p->name, &p->ten);
  26. fclose(fp);
  27. }
  28.  
  29. void output(Kojin *p)
  30. {
  31. FILE *fp = fopen("result.txt", "w");
  32. for (int i = 0; i < 5; ++i, p++)
  33. fprintf(fp, "%s %d\n", p->name, p->ten);
  34. fclose(fp);
  35. }
  36.  
  37. void data_sort(Kojin *p)
  38. {
  39. Kojin t;
  40. for (int i = 0; i < 5; ++i)
  41. for (int j = i + 1; j < 5; ++j)
  42. if (p[i].ten > p[j].ten)
  43. {
  44. t = p[i];
  45. p[i] = p[j];
  46. p[j] = t;
  47. }
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘input’:
prog.c:24: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:25: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result
prog.c: In function ‘output’:
prog.c:32: error: ‘for’ loop initial declaration used outside C99 mode
prog.c: In function ‘data_sort’:
prog.c:40: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:41: error: ‘for’ loop initial declaration used outside C99 mode
stdout
Standard output is empty