I could have sworn he had the array name there when I looked for it. Oh well.
The delimiter doesn't have to be mutable. In fact, it shouldn't be modified at all by strtok at all. Since arrays degrade to pointers to their type when passed to functions anyway, this would serve no purpose (since it isn't modified by the function).
I do wonder however, what he's passing to this function as an argument. He has down that it's an array of ints.
Code:
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
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);
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;
}
int main( void )
{
int array[10] = {0};
int f, c;
printf( "> " );
fflush( stdout );
f = freqInput( array );
for( c = 0; c < f && c < sizeof array / sizeof array[0]; c++ )
printf( "array[ %d ] is %d\n", c, array[ c ] );
return 0;
}
Quick test case shows it working fine for me. I suspect they're doing a few things wrong:
1 - Not initializing the array they're passing it.
2 - Not filling it completely.
3 - Printing the entire array, not only the filled cells.
Quzah.