Re: 程設
我剛剛問的
我也不會寫
#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;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.87.123 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1670381288.A.40C.html
→
12/07 10:48,
3年前
, 1F
12/07 10:48, 1F
→
12/07 10:48,
3年前
, 2F
12/07 10:48, 2F
→
12/07 10:49,
3年前
, 3F
12/07 10:49, 3F
我用中文問的 但他回答好像預設英文 可以叫他回答中文 超屌
→
12/07 10:49,
3年前
, 4F
12/07 10:49, 4F
※ 編輯: wwndbk (140.113.87.123 臺灣), 12/07/2022 10:52:17
→
12/07 10:53,
3年前
, 5F
12/07 10:53, 5F

我也不知道 可能我第一句跟他說hi
他就預設我是英文使用者
※ 編輯: wwndbk (140.113.87.123 臺灣), 12/07/2022 10:55:28
推
12/07 10:56,
3年前
, 6F
12/07 10:56, 6F
推
12/07 10:59,
3年前
, 7F
12/07 10:59, 7F
→
12/07 11:01,
3年前
, 8F
12/07 11:01, 8F
討論串 (同標題文章)