fork download
  1. #include <stdio.h>
  2. #define N 30
  3. typedef struct seito
  4. {
  5. int num;
  6. char lname[20];
  7. char fname[20];
  8. int point;
  9. } seito;
  10.  
  11.  
  12. int main(void)
  13. {
  14. seito d[N], t;
  15. char buf[100];
  16. FILE *fp = fopen("seito.dat", "r");
  17. int cnt = 0, i = 0, j, cmpCnt = 0;
  18. while (fgets(buf, 100, fp) != NULL)
  19. {
  20. sscanf(buf, "%d %s %s %d", &d[i].num, d[i].lname, d[i].fname, &d[i].point);
  21. i++;
  22. }
  23. cnt = i;
  24. for (i = 1; i < cnt; i++)
  25. {
  26. t = d[i];
  27. cmpCnt++;
  28. if (d[i - 1].point < t.point)
  29. {
  30. j = i;
  31. do
  32. {
  33. d[j] = d[j - 1];
  34. j--;
  35. cmpCnt++;
  36. }
  37. while (j > 0 && d[j - 1].point < t.point);
  38. d[j] = t;
  39. }
  40. }
  41. printf("番号 氏名 得点\n");
  42. for (int i = 0; i < cnt; ++i)
  43. {
  44. printf("%4d %-10s %-10s %4d\n", d[i].num, d[i].lname, d[i].fname, d[i].point);
  45. }
  46. printf("整列の為の比較回数=%d回\n", cmpCnt);
  47. return 0;
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:42: error: redefinition of ‘i’
prog.c:17: error: previous definition of ‘i’ was here
prog.c:42: error: ‘for’ loop initial declaration used outside C99 mode
stdout
Standard output is empty