Hey guys can somebody help me debug this problem. For some reason it tokenizez the first character correctly but then messes all the rest of the characters and i end up with mumbo jumpbo bogus input where half of the input is only correct. Any idea's?
Code:int freqInput(int *array)
{
/* declaration of variables*/
char *delim = " ";
char chInput[255];
char *p = chInput;
int count = 0;
/* call to user input*/
fgets(chInput, 255, stdin);
/*check for buffer overflow*/
if(chInput[strlen(chInput)-1] !='\n')
{
readRestOfLine();
return 0;
}
else
{
/*replace enter with Null '\0' */
chInput[strlen(chInput)-1] = '\0';
}
/*string tokenize*/
/*checking for NULL*/
/* checking for null character*/
/* tokenize the start of the input with a space*/
p = strtok(chInput, delim);
/* get the rest of the input tokenized until
there is none left then convert it to a
int and place it each element of the array*/
while(p != NULL)
{
array[count++] = (int) strtol(p, NULL, 10);
p = strtok(NULL, delim);
}
/* pass it back to options.c*/
return count;
}