我刚刚问的
我也不会写
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define a struct for the nodes in the linked list
struct Node
{
char* name;
int score;
int studentID;
struct Node* next;
};
int main()
{
// Open the text file in read mode
FILE* input = fopen("text.txt", "r");
// Read the data from the file and print it to the console
char line[256];
while (fgets(line, sizeof(line), input))
{
printf("%s", line);
}
// Close the file
fclose(input);
// Create the first node in the list
struct Node* head = malloc(sizeof(struct Node));
head->name = "Alice";
head->score = 100;
head->studentID = 123456;
// Create the second node in the list
struct Node* second = malloc(sizeof(struct Node));
second->name = "Bob";
second->score = 95;
second->studentID = 234567;
// Link the two nodes together
head->next = second;
// Read the input value
int input;
scanf("%d", &input);
// Loop through the list and output the data in the specified order
struct Node* current = head;
while (current != NULL)
{
if (input == 123)
{
printf("%s %d %d\n", current->name, current->score,
current->studentID);
}
else if (input == 213)
{
printf("%d %s %d\n", current->score, current->name,
current->studentID);
}
current = current->next;
}
return 0;
}