0

C でプログラムを書いていて、構造体の配列をファイルに保存しようとしています。私の意図は、構造体の配列を初期化し、それをファイルに保存することです。さらに、struct-entry 1、struct-entry 2、struct-entry 3 などのエントリを変更したいのですが、エントリがファイルに書き込まれません。構造体の配列が存在しないようです。

配列がファイルに書き込まれない理由がわからないので、助けていただければ幸いです。

スレックスありがとう

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct liste {
    unsigned int code;
    unsigned int activ;
    };
int main()
{
int z;

printf("Enter Index: "); /* Data should fill the z-th entry in array of structures */
scanf("%d",&z);

FILE *mrp;
struct liste bauteil[5]; /* Array with 5 structs for 5 different entries */

mrp = fopen("aaa.txt","w+b");

printf("Number of entry is: %d\n",z);
printf("Enter code: ");
scanf("%d",&bauteil[z].code);
bauteil[z].activ=77777; /* activ entry contains 77777 */

fseek(mrp, z * sizeof(struct liste), SEEK_SET);
fwrite(&bauteil[],sizeof(bauteil),1,mrp);

fclose(mrp);
return 0;
}
4

2 に答える 2

0

mrp = fopen("aaa.txt","r+b");
fwrite(&bauteil[z],sizeof(struct liste),1,mrp);
于 2013-04-11T22:33:57.307 に答える