读取和写入结构数组到二进制文件c99

时间:2017-11-22 11:58:54

标签: c struct file-io c99

我有一个用C实现的HashMap的基本版本。但是,我试图保存并从二进制文件加载它。但是,在此过程中,我将丢失数组中保存的数据。我很确定这是我的sizeof(hashMap)逻辑中的一个错误。

hashMap结构:

private void refreshSessionWithNewAuthorities(Collection<GrantedAuthority> authorities) {
    Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
    Authentication newAuth = new UsernamePasswordAuthenticationToken(currentAuth.getPrincipal(), currentAuth.getCredentials(), authorities);

    SecurityContextHolder.getContext().setAuthentication(newAuth);
}

数组的删除

typedef struct bucket{
int Hash;
int Key;
}BUCKET;

typedef struct node{
struct bucket data;
struct node * next;
}NODE;

typedef struct base{
struct node * head;
int length;
}BASE;

保存代码:

BASE * hashMap[hashMapWidth]

加载代码:

 printf("Saving to File\n");
 FILE *fr = fopen("LinkedListArray.bin", "wb");
 fwrite(hashMap, 1, sizeof(hashMap), fr);
 fclose(fr);

0 个答案:

没有答案