C 函数中的指针“获取”;必须是可修改的左值“;错误

C 函数中的指针“获取”;必须是可修改的左值“;错误,c,pointers,struct,dynamic-memory-allocation,C,Pointers,Struct,Dynamic Memory Allocation,我有一个小问题——出于某种原因,当我试图将内存重新分配到指向结构指针的指针,以将函数中额外结构的内存块数量增加1时,Intellisense告诉我“表达式必须是可修改的左值”。问题是,如果我尝试分配到输入本身,一切都很好-问题是当我尝试重新分配到输入+1时 正在使用的结构: struct Entry_t { char *word; Year **years; char **syn; Meaning **mean; Entry *next; }; stru

我有一个小问题——出于某种原因,当我试图将内存重新分配到指向结构指针的指针,以将函数中额外结构的内存块数量增加1时,Intellisense告诉我“表达式必须是可修改的左值”。问题是,如果我尝试分配到
输入
本身,一切都很好-问题是当我尝试重新分配到
输入+1

正在使用的结构:

struct Entry_t
{
    char *word;
    Year **years;
    char **syn;
    Meaning **mean;
    Entry *next;
};

struct Mean_t
{
    char *word;
    Entry **enword;
    Meaning *next;
};
职能:

/*
| Function: IsInMean
| Action: Checks whether the meaning already exists
| Input: Master meaning struct, the string
| Returns: The address of the necessary place if yes, NULL otherwise
*/
Meaning *IsInMean(Meaning *MEANS, char *str)
{
    if(MEANS)
    {
        if(strcmp(MEANS->word,str) == 0)
            return MEANS;
        else
            return IsInMean(MEANS + 1,str);
    }
    else
        return MEANS;
}

/*
| Function: FindMeanPlace
| Action: Checks where to wedge the meaning.
| Input: The master Meanings dictionary, the string
| Returns: The address of the place where to wedge, NULL if all are bigger.
*/
Meaning *FindMeanPlace(Meaning *MEANS, char *str)
{
    int cmp;
    if((cmp = strcmp(MEANS->word,str)) > 0)
        return NULL;
    else if(cmp < 0 && strcmp(MEANS->next->word,str) > 0)
        return MEANS;
    else
        return FindMeanPlace(MEANS + 1,str);
}

/*
| Function: NewMean
| Action: Creates and initializes a new meaning struct
| and places in it a new entry
| Input: Standard input, new entry, string with the meaning
| Returns: The address of the new meaning struct
*/
Meaning *NewMean(STANDARD_INPUT,Entry *new_e, char *str)
{
    Meaning *temp = (Meaning*)malloc(sizeof(Meaning));
    InitMean(temp);
    temp->word = (char*)calloc(strlen(str) + 1,sizeof(char));
    strcpy(temp->word,str);
    *(temp->enword) = new_e;
    return temp;
}

/*
| Function: SetMean
| Action: Sets the meanings field of an entry
| Input: Standard input, address of the new entry and
| the appropriate sub-string
| Returns: nada
*/
void SetMean(STANDARD_INPUT, Entry *new_e, char *str)
{
    char *cutout, delim[] = ",_";
    char **temp = NULL;
    int len = 0, cmp, index;
    Entry **entemp, *etemp;
    Meaning *input, *mtemp;
    cutout = strtok(str,delim);
    while(cutout)
    {
        temp = (char**)realloc(temp,(len + 1)*sizeof(char*));
        if(!temp)
            Pexit(STANDARD_C);
        *temp = (char*)calloc(strlen(cutout) + 1,sizeof(char));
        if(!(*temp))
            Pexit(STANDARD_C);
        strcpy(*temp,cutout);
        temp++;
        len++;
        cutout = strtok(NULL,delim);
    }
    QsortCust(STANDARD_C,temp,len + 1);
    while(temp)
    {
        index = 0;
        if(input = IsInMean(MEANS,*temp))
        {
            entemp = input->enword;
            if(strcmp(entemp[0]->word,new_e->word) > 0)
                //entemp + 1 = (Entry**)realloc(entemp,sizeof(entemp) + sizeof(Entry*));  "expression must be modifiable lvalue"
            while(entemp + index)
            {
                if((cmp = strcmp((entemp[index])->word,new_e->word)) < 0 && strcmp((entemp[index + 1])->word,new_e->word) > 0)
                {
                    //(entemp + index + 1) = (Entry**)realloc(entemp + index,sizeof(entemp + index) + sizeof(Entry*));  "expression must be modifiable lvalue"
                    //if(!(entemp + index + 1))
                    //  Pexit(STANDARD_C);
                }
                else if(cmp <0)
                {
                    index++;
                }
            }
        }
        else
        {
            input = FindMeanPlace(MEANS,*temp);
            mtemp  = input->next;
            input->next = NewMean(STANDARD_C,new_e,*temp);
        }
    }
}
/*
|职能:伊森曼
|操作:检查含义是否已经存在
|输入:主意思结构,字符串
|返回:必要位置的地址(如果是),否则为空
*/
意为*IsInMean(意为*MEANS,char*str)
{
如果(意味着)
{
如果(strcmp(意思->单词,str)==0)
返回方式;
其他的
返回IsInMean(表示+1,str);
}
其他的
返回方式;
}
/*
|功能:FindMeanPlace
|措施:检查在何处插入含义。
|输入:主词义词典,字符串
|返回:楔块所在位置的地址,如果所有楔块都较大,则为NULL。
*/
意为*FindMeanPlace(意为*MEANS,char*str)
{
int-cmp;
如果((cmp=strcmp(MEANS->word,str))>0)
返回NULL;
如果(cmp<0&&strcmp(MEANS->next->word,str)>0)
返回方式;
其他的
返回FindMeanPlace(表示+1,str);
}
/*
|函数:NewMean
|操作:创建并初始化一个新的语义结构
|并在其中放置一个新条目
|输入:标准输入,新条目,带含义的字符串
|返回:新语义结构的地址
*/
含义*NewMean(标准输入,条目*new\u e,字符*str)
{
含义*临时=(含义*)malloc(sizeof(含义));
初始平均温度;
temp->word=(char*)calloc(strlen(str)+1,sizeof(char));
strcpy(temp->word,str);
*(temp->enword)=新建;
返回温度;
}
/*
|函数:SetMean
|操作:设置条目的含义字段
|输入:标准输入、新条目的地址和
|适当的子字符串
|返回:nada
*/
void SetMean(标准输入,条目*新建,字符*str)
{
字符*剪切,delim[]=“,u”;
字符**temp=NULL;
int len=0,cmp,索引;
条目**entemp,*etemp;
含义*输入,*mtemp;
断路器=strtok(str,delim);
while(断开)
{
temp=(char**)realloc(temp,(len+1)*sizeof(char*);
如果(!temp)
Pexit(标准C);
*temp=(char*)calloc(strlen(cutout)+1,sizeof(char));
如果(!(*温度))
Pexit(标准C);
strcpy(*温度,断路器);
temp++;
len++;
断开=strtok(空,delim);
}
QsortCust(标准、温度、透镜+1);
while(临时)
{
指数=0;
如果(输入=IsInMean(表示,*temp))
{
entemp=input->enword;
if(strcmp(entemp[0]->word,new\u e->word)>0)
//entemp+1=(条目**)realloc(entemp,sizeof(entemp)+sizeof(条目*);“表达式必须是可修改的左值”
while(entemp+索引)
{
如果((cmp=strcmp((entemp[index])->word,new\u e->word))<0&&strcmp((entemp[index+1])->word,new\u e->word)>0)
{
//(entemp+index+1)=(条目**)realloc(entemp+index,sizeof(entemp+index)+sizeof(条目*);“表达式必须是可修改的左值”
//如果(!(entemp+索引+1))
//Pexit(标准C);
}
否则如果(下一步;
输入->下一步=新平均值(标准C、新e、*温度);
}
}
}
标准输入被定义为主词典(第一个条目*)、年度词典(第一年*)和含义词典(第一个含义*)。标准输入被定义为标准输入中变量的名称。

如果您想做什么(根据注释)是放大摄影矢量entemp本身,但在开头而不是结尾添加新的空格,您无法通过单个操作来完成此操作。
realloc
必须始终传递从
malloc
接收到的未偏移指针(或
calloc
或先前调用
realloc
),并且它总是在末尾添加空格。您必须使用
memmove
将所有内容向下滑动。例如:

nelements += 1;
entemp = realloc(entemp, nelements * sizeof(Entry *));
assert(entemp);
memmove(entemp, entemp+1, (nelements - 1) * sizeof(Entry *));
另外,正如我刚才注意到的:
sizeof(entemp)
不返回
entemp
指向的内存块的分配大小。它返回指针本身的大小。无法检索C堆上块的分配大小;您必须自己跟踪它们。这就是上面我的
nelements
变量所做的

密切相关的强制性切分注释:不要强制转换
realloc
的返回值,就像你不强制转换
malloc
calloc
的返回值一样。这不仅仅是一个样式问题:不需要时强制转换可以隐藏bug


不太密切相关但仍然是强制性的风格挑剔:
名称在所有大写字母中都是为常量保留的。不要将它们用于变量名称。而扩展到整个变量/参数声明的神奇宏是正确的。

事实上,我希望
entemp+1
-我想增加通过一个条目*指针将其引导到的空间量,并将指针向右移动一个空间.这是一种片面的排序尝试。如果你有任何不同/正确的建议,请说出来-我不是最熟练的人。@casting-我恐怕是被迫这样做的,因为这是课程老师的要求。啊。你不能用
realloc
自己来做。请参阅编辑,它将在短时间内发生Y