Hello there.
I'm (kind of) new to programming as you can see, and I have a question.
I want the user to input a string (for example: a product code) but store it dynamically. There must be an other way instead of a static array with, let's say, 50 elements. What I have been trying is this:
However, I always seem to get (null) as the printf result. I even tryed setting a counter and printing the *(w-counter) result but yet again... no luck. Any help really appreciated. :)
(By the way, on a side note. Is there any way I can avoid the declaration of "test" and "w=&test"?)
Thank you very much. :)
I'm (kind of) new to programming as you can see, and I have a question.
I want the user to input a string (for example: a product code) but store it dynamically. There must be an other way instead of a static array with, let's say, 50 elements. What I have been trying is this:
Code:
int c;
char *w, test;
w=&test;
printf("Give product code: ");
while (c = getchar() != EOF)
{
*w=c;
w=w+1;
}
w=w+1;
*w='\0';
printf("%s", *w);
(By the way, on a side note. Is there any way I can avoid the declaration of "test" and "w=&test"?)
Thank you very much. :)
Comment