gpt4 book ai didi

c++ - 传递字符串数组时出现段错误

转载 作者:行者123 更新时间:2023-11-28 03:11:21 26 4
gpt4 key购买 nike

<分区>

我在 stackoverflow 上遇到了类似的问题,但它没有解决我的问题

我正在尝试发送如下字符串数组

void manipulateString( char *);
int hashTable (int &, char * );
const int HTsize = 10;
int main()
{
const int size = 100;
char inputString[size];

cout << " Enter first names ( separate by a space ) \n ";
cin.getline(inputString,size);

manipulateString(inputString);

return 0;
}

void manipulateString (char *input)
{

int firstNamelen;
int hIndex=0,newIndex=0;
int totalName = 0;

char *firstname;
firstname = strtok(input, " "); // separate firstname

while (firstname != NULL)
{

firstNamelen = strlen(firstname);
hIndex = hashfunction(firstname,firstNamelen);

newIndex=hashTable(hIndex, firstname);
cout << "\n\n ( " << firstname << " ) is stored at index [" << hIndex << "] of hash table " << endl;

firstname = strtok(NULL, " " ); // next first name

}
}

当它到达 void manipulateString (char *input) 时,它给出了段错误。有什么问题?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com