想將個txt檔案讀取到結構陣列,可做到這不會了,求助
1樓:網友
資料格式設計的不一致,請忽略c++的差異。
#include ""
#include
#include
using namespace std;
struct user_rating
int userid;
int movieid;
float rates;
int main()
file *fp = null;
errno_t err;
int i = 0, j;
struct user_rating ur[100];
printf("can't open it");
exit(exit_failure);
while (!feof(fp))
i++;j = i;
for (i = 0; i < j; i++)printf("%2d, %4d, %", ur[i].userid, ur[i].movieid, ur[i].rates);
fclose(fp);
system("pause");
return 0;
2樓:網友
同學,請獨立完成自己的作業。
如何將乙個txt檔案中的內容存入乙個結構體陣列中???
3樓:網友
把文字中內容讀取出來,提取出你想要的資訊,乙個乙個賦值到你的結構體中去。
請問怎麼把這個txt檔案裡的資料對應讀到我寫的結構體陣列裡
4樓:金色潛鳥
陣列 size 要給定大小。
float money1, money2, 精度不夠 須用 double, 格式 %lf
按你規定,資料用分號分隔,ascii 文字檔案。
#include
#define size 100
struct datatable data [size];
int main();
n=i;printf("%10s %f",data[n-1].time,data[n-1].money2);
return 0;}
如何將txt檔案中的學生資訊讀取到結構體陣列中,c語言
5樓:忽忽上公升
file *fp;
printf("請輸入檔名,路徑:"); //開啟txt檔案scanf("%s",filename);
if((fp = fopen(filename,"r")) == null)
for(int i=0; i<12; i++)//迴圈讀取。
跪求!!c語言怎樣實現從txt檔案中讀取資料並存入結構陣列??
6樓:網友
宣告乙個struct data 物件 假如是data,一次讀取乙個data的資料,那麼即可。
7樓:網友
號碼 姓名 得分1 得分2 得分3 ..得分很多? 12個?是不是確切的?)
如何把乙個txt文件讀取到乙個一維陣列裡
8樓:牽絆_背心
先讀資料,然後遇到乙個空格或者換行符就把它賦值給陣列。
怎樣把txt格式檔案中以記錄存在的資料讀到c語言結構體陣列中
9樓:扶扶眼鏡
#include
#include
struct content
int main()
struct content *p1,*p2=null;
p1=(struct content*)calloc(1,sizeof(struct content));
p2=p1;
while (fscanf(fp,"%s",p1->id)==-1)return 0;
這是**,沒測試過,不知道對吧,高手不敢當,希望對你有用。
10樓:匿名使用者
首先你得知道檔案記錄的格式是什麼樣的。
比如說,檔案中存的是學生的成績。
學號 語文 數學。
1、定義結構體資訊。
struct student
2、定義乙個結構體陣列,用來存所有學生的資訊struct student s[100];
3、讀取每一行資訊。
c語言從文字檔案讀取資料到結構體陣列中的問題
11樓:金色潛鳥
關鍵問題是用 逗號分隔的 字串 ,不能用 逗號格式 這樣分開地讀出來。
要用 "%[^f" 格式 才行。
另外 讀引數用 &temp[n].mark 才行,你漏了 &.
你先用下面程式讀2行,01010101,ababcevvz,020202,efgwe,試驗成功再讀全部。
#include
#include
struct student
typedef struct student stu;
stu *temp;
int main()
fclose(fp);}
讀完的控制用 if (fscanf(..==eof) break;
VB讀取和寫入問題,VB讀取和寫入txt問題
很簡單啊 先讀檔案,然後轉換成string,再用left命令分別取那幾個數字 寫入的話也不難,將那幾個string加到一塊就行 然後寫檔案 vb逐行讀取和逐行寫入txt的問題 vb寫入txt檔案 open 1.txt for output as 1for i 1 to 10 print 1,trim...
想用c 讀取檔案。檔案內容如下
很簡單 我來寫 2011 03 01 00 00 00,9001,0011156,92,10,87303291,150262852 2011 03 01 00 00 00,9001,0011156,3,10,87303289,216000651 press any key to continue i...
讀取服務端檔案,ASP讀取服務端TXT檔案裡的HTML程式碼
return the response.webresponse myresponse code to use the webresponse goes here.這就是他的大小了。close the response to free resources.flex 如何讀取服務端的 xml檔案 建立h...