0
你好這是我學習c編程的第一年,我花了整整一天的時間試圖找出這一個,現在我頭痛 無論如何,我只是想保持這個儘可能簡單,這裏是一個測試代碼,我想糾正,所以我可以理解這是如何工作的 我想要做的是在文本文件中存儲結構變量的動態數組,然後從該文本文件中讀取數據一個動態數組。 這是c語言以c語言在文本文件中存儲結構的動態數組
#include <stdio.h>
#include <stdlib.h>
struct student {
char nam[3]; // we store to this
char testname[3]; // we read to this
}*science[10];
int main() {
int i;
FILE *ptr=fopen("science_class","a");
for (i=0;i<3;i++){ //storing the infro from dynamic array into the file
e[i]=(science*)calloc(3,sizeof(char));
puts("enter name");
gets(science[i]->name);
fprintf(ptr,"%s",science[i]->name); }
for (i=0;i<3;i++){ // loading the info from the file to a dynamic array
fscanf(ptr,"%s",&science[i]->testname)
printf("name :%s \n",science[i]->testname) }
fclose(ptr);
}
這是什麼人做的,它需要的第一個文件的內容,並把它複製到第二個文件, 我更換第一個fscanf行與此 scanf(「%s」,cars [i] .name); scanf(「%s」,cars [i] .color); scanf(「%f」,&cars [i] .mass); 012fscanf(「%i」,&cars [i] .price); 所以我可以手動輸入數據,但程序後,我已完成鍵入他們的手指,我仍然不能存儲在文本文件中的數據可以ü請幫助我, –
對不起,我回答這麼晚,希望你明白,我不知道我的英語說得很好 –
對不起,我剛剛有機會回覆,非常感謝你的幫助,它幫助我理解了這是如何工作的,我非常感謝你的幫助 –