C++ 值类型const char不能用于初始化char类型的实体*

C++ 值类型const char不能用于初始化char类型的实体*,c++,constants,C++,Constants,我的代码存在以下问题,尽管编译正确: 值类型const char不能用于初始化char类型的实体* 有人能帮我吗?我可以运行代码,这很奇怪,但我不能用它创建一个makefile。我觉得很奇怪 int SpliString(struct dict_word *entry, const char *str) { long word_length,j,k; int yearIndex; char *buffer; char *endOfYears; char *endOfYear; char *en

我的代码存在以下问题,尽管编译正确:

值类型const char不能用于初始化char类型的实体*

有人能帮我吗?我可以运行代码,这很奇怪,但我不能用它创建一个makefile。我觉得很奇怪

int SpliString(struct dict_word *entry, const char *str)
{
long word_length,j,k;

int yearIndex;
char *buffer;
char *endOfYears;
char *endOfYear;
char *endOfDefinition;
char *endOfWord = strstr(str, "_#_");

   //Sets the first num bytes of the block of memory pointed by ptr
  //to the specified value (related as an unsigned char)
memset(entry, 0, sizeof(struct dict_word));

  // If '_#_' is not found, it's NULL
    if (endOfWord)
{
    // Calculating word legth; 'str' points to start of word, 'endofWord' points to '_#_' that is just after word
    word_length = endOfWord - str;

    // Copying data into the word
    strncpy(entry->words, str, word_length);

    // 'endOfYears' points to '_#_,' but wee need to find follow '_#_'
    // therefore there is added 3 in order to skip curremnt '_#_
    endOfYears = strstr(endOfWord+3, "_#_");

    if (endOfYears)
    {
        word_length = endOfYears - (endOfWord+3);
        // Skips _#_
        buffer = endOfWord+3;
        yearIndex = 0;
        j = 0;

        // Finds next year in the line, it stops if all 10 years is filled
        // or end of years string is reached
        while(yearIndex<10 && buffer+j<endOfYears)
        {
            // Stores year in the buffer, with converting 'stirng' to 'int'
            entry->year[yearIndex] = atoi(buffer+j);
            // check year for negative...
            if (entry->year[yearIndex]<=0)
                return 0;

            // Locating substring; 'j' is current offset from beginning of buffer
            endOfYear = strchr(buffer+j, '_');

            if (endOfYear)
            {
                j = endOfYear - buffer;
                j++;
                yearIndex++;
            }
            else
            {
                break;
            }
        }

        //endOfYears points to '_#_' that separatates 'years' and 'definition'
        //and there is needed to find '_#_' between 'definition' and 'synonyms'
        //therefore it skips '_#_' that separatates 'years' and 'definition',
        //+3, because '_#_' has length = 3
        endOfDefinition = strstr(endOfYears+3, "_#_");
        if (endOfDefinition)
        {
            word_length = endOfDefinition - (endOfYears+3);
            k = 0;

            for(j=0; j<word_length; j++)
            {
                // Skips '_#_'
                if (endOfYears[j+3]==',')
                {
                    entry->eng_synonyms[k] = ' ';
                    k++;
                }
                else if (endOfYears[j+3]>='a' && endOfYears[j+3]<='z')
                {
                    entry->eng_synonyms[k] = endOfYears[j+3];
                    k++;
                }
                else if (endOfYears[j+3]!='_')
                {
                    return 0;
                }
            }

            k = 0;
            word_length = (str+strlen(str)) - (endOfDefinition+3);

            for(j=0; j<word_length; j++)
            {
                if (endOfDefinition[j+3]==',')
                {
                    entry->heb_synonyms[k] = ' ';
                    k++;
                }
                else if (endOfDefinition[j+3]>='A' && endOfDefinition[j+3]<='Z')
                {
                    entry->heb_synonyms[k] = endOfDefinition[j+3];
                    k++;
                }
                else if (endOfDefinition[j+3]!='_')
                {
                    return 0;
                }
            }
        }

        // Check for legality
        // Check all symbols of 'entry->words'
        // calculate length and supress warning
        for(j=0;j<(int)strlen(entry->words);j++)
        {
            if (entry->words[j]<'a' || entry->words[j]>'z')
                return 0;
        }

        return 1;
    }
}
return 0;
}
int-SpliString(结构dict_-word*entry,常量char*str)
{
长字长,j,k;
国际年指数;
字符*缓冲区;
char*endOfYears;
char*endOfYear;
字符*内定义;
char*endoford=strstrstr(str,“##"”);
//设置ptr指向的内存块的第一个num字节
//指定的值(作为无符号字符相关)
memset(entry,0,sizeof(struct dict_word));
//如果找不到“35; 35;”,则为空
if(endoford)
{
//计算单词长度;“str”指向单词的开头,“endofWord”指向单词后面的“35; 35;”
单词长度=endOfWord-str;
//将数据复制到word中
strncpy(输入->单词、str、单词长度);
//“Endofyear”指向“35; uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
//因此,增加了3以跳过当前'_#_
endOfYears=strstrstr(endoford+3,“####”;
如果(endOfYears)
{
单词长度=endOfYears-(endOfWord+3);
//跳过_#_
缓冲区=endoford+3;
年指数=0;
j=0;
//在该行中查找下一年,如果所有10年都已满,则该行将停止
//或达到年结束字符串
而(yearIndexeer[yearIndex]='a'&&endOfYears[j+3]eng_同义词[k]=endOfYears[j+3];;
k++;
}
else if(endOfYears[j+3]!=“”)
{
返回0;
}
}
k=0;
单词长度=(str+strlen(str))-(endOfDefinition+3);
对于(j=0;jheb_同义词[k]='';
k++;
}
else if(endOfDefinition[j+3]>='A'&&endOfDefinition[j+3]heb_同义词[k]=endOfDefinition[j+3];
k++;
}
else if(endOfDefinition[j+3]!=“”)
{
返回0;
}
}
}
//检查合法性
//检查“输入->单词”的所有符号
//计算长度并消除警告
对于(j=0;jwords);j++)
{
如果(输入->单词[j]单词[j]>'z')
返回0;
}
返回1;
}
}
返回0;
}
使用

自信OP是在C++中编译的.< /P>

// C
char *strstr(const char *s1, const char *s2);
// C++
const char* strstr(const char* s1, const char* s2);
char* strstr( char* s1, const char* s2);


使用

自信OP是在C++中编译的.< /P>

// C
char *strstr(const char *s1, const char *s2);
// C++
const char* strstr(const char* s1, const char* s2);
char* strstr( char* s1, const char* s2);


使用

自信OP是在C++中编译的.< /P>

// C
char *strstr(const char *s1, const char *s2);
// C++
const char* strstr(const char* s1, const char* s2);
char* strstr( char* s1, const char* s2);


使用

自信OP是在C++中编译的.< /P>

// C
char *strstr(const char *s1, const char *s2);
// C++
const char* strstr(const char* s1, const char* s2);
char* strstr( char* s1, const char* s2);




<>代码>结构> DistaWord < /Cord>。这是什么错误?你说它编译正确,然后列出什么是编译器错误。哪一行是错误的?你是指你可以运行代码,但不能创建一个MaCo文件?这里缺少重要信息。你可能使用C++,编译I.C.你的文件。扩展名可以是C,但如果
char*endOfWord=strstrstr(str,“##"”)则会出现错误错误代码是什么?你说它编译正确,但是列出什么是编译器错误。哪一行是错误的?你是指你可以运行代码,但不能创建一个MaFo文件?这里缺少重要信息。你可能使用C++。+,编译i C。您的文件扩展名可能是C,但如果
char*endOfWord=strstrstr(str,“##"”)则会出现错误错误代码是什么?你说它编译正确,但是列出什么是编译器错误。哪一行是错误的?你是指你可以运行代码,但不能创建一个MaFo文件?这里缺少重要信息。你可能使用C++。+,编译i C。您的文件扩展名可能是C,但如果
char*endOfWord=strstrstr(str,“##"”)则会出现错误错误代码是什么?你说它编译正确,但是列出什么是编译器错误。哪一行是错误的?你是指你可以运行代码,但不能创建一个MaFo文件?这里缺少重要信息。你可能使用C++。+文件编译扩展名可以是C,但是如果代码为> > char * EndoWord=STRSTR(STR),“<代码”>,则错误是你得到的,是用C++编译的。