Forked Function not assigning pointer
- by Luke Mcneice
In the code below I have a function int GetTempString(char Query[]);
calling it in main works fine.
However, when calling the function from a fork the fork hangs (stops running, no errors, no output) before this line: pch = strtok (Query," ,"); the printf shows that the pointer to pch is null. Again this only happens when the fork is executing it.
What am I doing doing wrong?
int main()
{
if((Timer =fork())==-1) printf("Timer Fork Failed");
else if(Timer==0)
{
while(1)
{
sleep(2);
GetTempString("ch 1,2,3,4");
}
}
else
{
//CODE
GetTempString("ch 1,2,3,4");
}
}
int GetTempString(char Query[])
{
char * pch;
printf("DEBUG: '%s'-'%d'\n",Query,pch);
pch = strtok (Query," ,");//* PROBLEM HERE*
//while loop for strtok...
return 1;
}