is it a pointer?

Hi guys,

I haven't coded c++ for more than 5 years and need some help. I got following code and can't tell if the "*" is pointer or it's something else, especially the line *token = strtok(buffer, " \t");

Could you please give me a explaination of what each line does.

Thanks in advance,

Jonathan.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void ParseString(char *buffer, int *argc, char **argv)
{
	/* tokenizes input string and generates argc, argv */
	int nw = 0;
	char *token = strtok(buffer, " \t");
	while (token != NULL)
	{
		if (token[0] != '\n')
		{
			argv[nw] = token;
			nw++;
		}
		token = strtok(NULL, " \t");
	}
	*argc = nw;
}
Last edited on
Each time you find a declaration with this format:

TYPE * NAME
NAME is a pointer to type.

Just notice this:
TYPE* var1, var2, *var3;
var1 and var3 are pointers while var2 is not

For strtok see
http://www.cplusplus.com/reference/clibrary/cstring/strtok/
Last edited on
Bazzy,

As i stated earlier, I haven't coded c++ for more than 5 years and need some help. I got code and can't tell if the "*" is pointer or it's something else, especially the line *token = strtok(buffer, " \t");

I need help understand this specific code so i can start working with it right away. I know how to declare a pointer, but from the code i posted above, i can't tell.

Could you please give me a explaination of what each line does.

The line is not *token = strtok(buffer, " \t");, the line is char *token = strtok(buffer, " \t"); which is in the form TYPE * NAME.
It is declaring token as a pointer to char, then getting a value from strtok.
If you want to know how strtok works see the link I gave you: http://www.cplusplus.com/reference/clibrary/cstring/strtok/
Topic archived. No new replies allowed.