I am trying to write 3 function: the first one: "read_comp" initialize a char pointer and assign it what function "readAndRemove" return. readAndRemove read line from the user and remove any spaces before the string and return a pointer to the string without the spaces in the start. then the "read_comp" print the string got by "readAndRemove" - the one without the spaces.
the last function - the one that i have problem with... function "findComplex": what i am trying this function to do is just to get char pointer and print the string that function got.
void read_comp(void)
{
char *str = readAndRemove();
printf("%s\n",str);
findComplex(&str);
}
-------------
char * readAndRemove() /**function to read rest of input and remove first space**/
{
char tempChar[30];
fgets(tempChar,30,stdin);
char* ptr = strtok(tempChar, " ");
return ptr;
}
--------------
void findComplex(char* str)
{
printf("in findComplex:%s\n",str);
}
(sorry if the start was irrelevant but i thought maybe there is problem with the way i am doing everything...)
so i tried to fix and change few things: change this: define char *str; as global parameter and chanege the function:
void read_comp(void)
{
*str = readAndRemove();
printf("%s\n",str);
findComplex(str);
}
char * readAndRemove() /**function to read rest of input and remove first space**/
{
char tempChar[30];
fgets(tempChar,30,stdin);
char* ptr = strtok(tempChar, " ");
return ptr;
}
void findComplex(char* str)
{
printf("%s\n",str);
printf("in findComplex:%s\n",str);
}