fork(2) download
  1. #define SIZE 5
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6.  
  7. void input(char fullname[][25], int age[]);
  8. void output(char fullname[][25], int age[]);
  9. void bubblesortname(char *fullname[], int *age, int size);
  10. void bubblesortage(char *fullname[], int *age, int size);
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. char fullname[SIZE][25];
  15. int age[SIZE];
  16.  
  17.  
  18.  
  19. // promt user for names and ages
  20. input(fullname, age);
  21. //output unsorted names and ages
  22. output(fullname, age);
  23.  
  24. bubblesortname(fullname,age,SIZE);
  25.  
  26. output(fullname, age);
  27.  
  28. //sorts age
  29. bubblesortage(fullname,age,SIZE);
  30. //
  31. output(fullname, age);
  32.  
  33.  
  34. return 0;
  35. }
  36.  
  37. void input(char fullname[][25], int age[])
  38. {
  39. int i;
  40. for (i = 0; i < SIZE; i++)
  41. {
  42. fflush(stdin);
  43. printf("Enter a full name\n");
  44. //scanf("%[\^n]\n", fullname[i]);
  45. fgets (fullname[i],40, stdin);
  46. printf("Enter the age\n");
  47. scanf("%d", &age[i]);
  48.  
  49. }
  50. }
  51.  
  52. void output(char fullname[][25], int age[])
  53. {
  54. int i;
  55. for (i = 0; i < SIZE; i++)
  56. printf("%s, %d\n", fullname[i], age[i]);
  57. }//end function
  58.  
  59. void bubblesortname(char *fullname[], int *age, int size)
  60. {
  61. int temp_age;
  62. char* temp_name;
  63. int j,i;
  64.  
  65. for (i = 0; i < SIZE - 1; ++i)
  66. {
  67. for (j = 0; i < SIZE - 1; ++j)
  68. {
  69. if (strcmp(fullname[j], fullname[j + 1]) > 0)
  70. {
  71. temp_age = age[i];
  72. age[j] = age[j + 1];
  73. age[j + 1] = temp_age;
  74.  
  75. temp_name = fullname[j];
  76. fullname[j] = fullname[j + 1];
  77. fullname[j + 1] = temp_name;
  78.  
  79.  
  80. }//end if
  81.  
  82. }//end inner for
  83.  
  84. }//end for
  85.  
  86. }//end function
  87.  
  88. bubblesortage(char *fullname[], int *ages, int size)
  89. {
  90. int j,i;
  91. int temp_age;
  92. char* temp_name;
  93. for (i = 0; i < size - 1; ++i)
  94. {
  95. for (j = 0; j < size - 1; ++j)
  96. {
  97. if (age[j] > age[j + 1])
  98. {
  99.  
  100. temp_age = age[j];
  101. age[j] = age[j + 1];
  102. age[j + 1] = temp_age;
  103. temp_name = fullname[j];
  104. fullname[j] = fullname[j + 1];
  105. fullname[j + 1] = temp_name;
  106.  
  107. }// end inner for
  108.  
  109. }// end outer for
  110.  
  111.  
  112. }// end function
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:24:22: warning: passing argument 1 of 'bubblesortname' from incompatible pointer type
       bubblesortname(fullname,age,SIZE);
                      ^
prog.c:9:8: note: expected 'char **' but argument is of type 'char (*)[25]'
   void bubblesortname(char *fullname[], int *age, int size);
        ^
prog.c:29:21: warning: passing argument 1 of 'bubblesortage' from incompatible pointer type
       bubblesortage(fullname,age,SIZE);
                     ^
prog.c:10:8: note: expected 'char **' but argument is of type 'char (*)[25]'
   void bubblesortage(char *fullname[], int *age, int size);
        ^
prog.c: At top level:
prog.c:88:5: warning: return type defaults to 'int' [-Wreturn-type]
     bubblesortage(char *fullname[], int *ages, int size) 
     ^
prog.c:88:5: warning: conflicting types for 'bubblesortage'
prog.c:10:8: note: previous declaration of 'bubblesortage' was here
   void bubblesortage(char *fullname[], int *age, int size);
        ^
prog.c: In function 'bubblesortage':
prog.c:97:19: error: 'age' undeclared (first use in this function)
               if (age[j] > age[j + 1]) 
                   ^
prog.c:97:19: note: each undeclared identifier is reported only once for each function it appears in
prog.c:112:8: error: expected declaration or statement at end of input
        }// end function
        ^
stdout
Standard output is empty