【发布时间】:2015-11-26 01:51:38
【问题描述】:
它要求我创建一个哈希函数,通过对邮政编码的字符求和来将其转换为整数。这是我的代码。我还没有接触到哈希函数。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct PostalCode
{
int size;
char *array[6];
} PostalCode;
int main()
{
int size = 6, i;
PostalCode *h = malloc(sizeof(PostalCode));
h->size = size;
h->array = malloc(sizeof(char)*size);
printf("Please enter your postal code: \n");
for (i=0; i<6; i++)
scanf(" %c", &(h->array[i]));
}
我现在得到的错误是:postalcode.c:9:11: error: assignment to expression with array type h->array = malloc(sizeof(char)*size);
【问题讨论】:
-
您正在声明一个数据类型为
Postalcode的变量名 -
char *array[6];-->char array[6];scanf(" %c", &(h->array[i]));TTFN -
我仍然得到完全相同的错误,我知道我需要 %c 和 & 虽然
-
这些错误消息看起来像是您正在尝试将源文件作为 shell 脚本执行。
-
顺便说一句,无论是什么要求您创建一个哈希函数,通过汇总邮政编码字符来询问它是什么意思。例如,如果邮政编码是 265541,那么和是 2 + 6 + 5 + 5 + 4 + 1 = 23,还是数字的 ASCII 码之和? :)