資源簡介
Q1077615.zip C++讀文件創建鏈表問題 https://ask.csdn.net/questions/1077615

代碼片段和文件信息
//?Q1077615.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?
using?namespace?std;
struct?student?
{
unsigned?long?id;
string?name;
float?score;
student?*next;?//下一個結點的指針
};
int?main()
{
student?head?=?{-1““0};
head.next?=?NULL;
student?*?p?=?&head;
FILE?*?fp?=?fopen(“Score.txt“?“r+“);
while?(true)
{
unsigned?long?id;
char?name[100];
float?score;
if?(fscanf(fp?“%ld%[^]%f“?&id?name?&score)?==?EOF)?break;
p->next?=?new?student;
p?=?p->next;
p->next?=?NULL;
p->id?=?id;
p->name?=?name;
p->score?=?score;
}
int?n;
while?(1)
{
cin?>>?n;
if?(n?==?0)?break;
p?=?head.next;
while?(p)
{
if?(p->id?==?n)
{
cout?<name?<“?“?<score?< break;
}
p?=?p->next;
}
if?(!p?||?p->id?!=?n)
cout?<“no?record!“?< }
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-05-24?13:36??Q1077615\Debug\
?????文件???????51712??2020-05-24?13:32??Q1077615\Debug\Q1077615.exe
?????文件?????????891??2020-05-24?13:15??Q1077615\Q1077615.sln
?????文件???????12288??2020-05-24?13:34??Q1077615\Q1077615.suo
?????目錄???????????0??2020-05-24?13:26??Q1077615\Q1077615\
?????目錄???????????0??2020-05-24?13:36??Q1077615\Q1077615\Debug\
?????文件?????????996??2020-05-24?13:32??Q1077615\Q1077615\Q1077615.cpp
?????文件????????4402??2020-05-24?13:26??Q1077615\Q1077615\Q1077615.vcxproj
?????文件????????1366??2020-05-24?13:26??Q1077615\Q1077615\Q1077615.vcxproj.filters
?????文件?????????143??2020-05-24?13:15??Q1077615\Q1077615\Q1077615.vcxproj.user
?????文件????????1722??2020-05-24?13:15??Q1077615\Q1077615\ReadMe.txt
?????文件?????????143??2020-05-24?13:19??Q1077615\Q1077615\Score.txt
?????文件?????????295??2020-05-24?13:15??Q1077615\Q1077615\stdafx.cpp
?????文件?????????320??2020-05-24?13:15??Q1077615\Q1077615\stdafx.h
?????文件?????????314??2020-05-24?13:15??Q1077615\Q1077615\targetver.h
評論
共有 條評論