D
Denis Palmeiro
Hi, I've been reading K&R, and I'm a bit confused. In the book,
they have the following function:
void writelines(char *lineptr[], int nlines )
{
while( nlines-- > 0 )
printf("%s\n", *lineptr++);
}
Now when I initialize:
char *lines[] = {"Hello", "Hey"};
and pass it as the first arg in that function, it works exactly
like expected.
However, if I try to do the same thing in main:
int main(void) {
char *lineptr[] = {"Hello", "Hey"};
int i = 2;
while( i-- > 0 )
printf("%s\n", *lineptr++);
return 0;
}
I get the error:
test.c:9: error: wrong type argument to increment
Now, how come I can increment lineptr in writelines, but not in
main. If it's declared as an argument, is it another type?
Also, if this is an array, how come it's possible to increment it
in the writelines function. I thought you can't change what an
array points to?
Thanks in advance,
Denis Palmeiro
they have the following function:
void writelines(char *lineptr[], int nlines )
{
while( nlines-- > 0 )
printf("%s\n", *lineptr++);
}
Now when I initialize:
char *lines[] = {"Hello", "Hey"};
and pass it as the first arg in that function, it works exactly
like expected.
However, if I try to do the same thing in main:
int main(void) {
char *lineptr[] = {"Hello", "Hey"};
int i = 2;
while( i-- > 0 )
printf("%s\n", *lineptr++);
return 0;
}
I get the error:
test.c:9: error: wrong type argument to increment
Now, how come I can increment lineptr in writelines, but not in
main. If it's declared as an argument, is it another type?
Also, if this is an array, how come it's possible to increment it
in the writelines function. I thought you can't change what an
array points to?
Thanks in advance,
Denis Palmeiro