Segmentation fault while passing string array
I went through similar question on stackoverflow but it did not solve my
issue
I am trying to send string array as below
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
}
}
When it reaches to void manipulateString (char *input) it gives
segmentation fault. what is the issue?
No comments:
Post a Comment