The first call to read the student file
The first call to read the student fileThe bubble sort
The bubble sortThe second call to read the student file, which may not be necessary.
void listing_id() { int line = -1; char temp[500], temp1[500], temp2[500], temp3[500]; long long unlisted_id[50], listed_id[50]; char string[500], stringgg[500];
filePtr = fopen("student_informations.txt", "r"); while (fgets(string, sizeof(string), filePtr) != NULL) { if (line == -1) { //fputs(string,stdout); } else { fscanf(filePtr, "%s %s %lld %s %s", temp, temp1, &listed_id[line], temp, temp1); unlisted_id[line] = listed_id[line]; } line++; } fclose(filePtr); long long hold; for (int i = 0; i < line - 2; i++) { //bubble sort for (int i = 0; i < line - 2; i++) { if (listed_id[i] > listed_id[i + 1]) { hold = listed_id[i + 1]; listed_id[i + 1] = listed_id[i]; listed_id[i] = hold; } } } int loop = 0; for (int i = 0; i < line - 1; i++) { filePtr = fopen("student_informations.txt", "r"); // opening and closing back so that while loop will work, and cursor will go back to the line 1 while (fgets(stringgg, sizeof(stringgg), filePtr) != NULL) { if (loop == 0 || loop == 1) { fputs(stringgg, stdout); loop++; } else { fscanf(filePtr, "%s %s %lld %s %s", temp, temp1, &unlisted_id[0], temp2, temp3); if (listed_id[i] == unlisted_id[0]) { printf("%s %s %lld %s %s\n", temp, temp1, listed_id[i], temp2, temp3); break; } } } fclose(filePtr); }
}
The second call to read the student file, which may not be necessary.
void listing_id() {
int line = -1;
char temp[500], temp1[500], temp2[500], temp3[500];
long long unlisted_id[50], listed_id[50];
char string[500], stringgg[500];
filePtr = fopen("student_informations.txt", "r");
while (fgets(string, sizeof(string), filePtr) != NULL) {
if (line == -1) {
//fputs(string,stdout);
}
else {
fscanf(filePtr, "%s %s %lld %s %s", temp, temp1, &listed_id[line], temp, temp1);
unlisted_id[line] = listed_id[line];
}
line++;
}
fclose(filePtr);
long long hold;
for (int i = 0; i < line - 2; i++) { //bubble sort
for (int i = 0; i < line - 2; i++) {
if (listed_id[i] > listed_id[i + 1]) {
hold = listed_id[i + 1];
listed_id[i + 1] = listed_id[i];
listed_id[i] = hold;
}
}
}
int loop = 0;
for (int i = 0; i < line - 1; i++) {
filePtr = fopen("student_informations.txt", "r"); // opening and closing back so that while loop will work, and cursor will go back to the line 1
while (fgets(stringgg, sizeof(stringgg), filePtr) != NULL) {
if (loop == 0 || loop == 1) {
fputs(stringgg, stdout);
loop++;
}
else {
fscanf(filePtr, "%s %s %lld %s %s", temp, temp1, &unlisted_id[0], temp2, temp3);
if (listed_id[i] == unlisted_id[0]) {
printf("%s %s %lld %s %s\n", temp, temp1, listed_id[i], temp2, temp3);
break;
}
}
}
fclose(filePtr);
}
}