Hello,
I just have a quick question to ask...
I am getting an "assignment from incompatible pointer type" in my code and I can't understand why.
I have actually got this program to compile and run without any errors now, but I would like to know the reason for the problem that was occuring, if anyone could help me out?
The program is very simple. It asks the user to input a string and uses a function for the inputting. I am still learning pointers so this is only for my own learning purposes.
Here is the bugged code.
Code:
#include <stdio.h>
main()
{
char input[50];
char *ptrInput;
ptrInput = &input;
puts("Enter a string: ");
my_scanf(ptrInput);
puts(input);
fflush(stdin);
getchar();
}
my_scanf(char *ptrInput)
{
gets(ptrInput);
}
Here is the working code. Can anyone tell me why a cast is required when I'm using the same type?
Code:
#include <stdio.h>
main()
{
char input[50];
char *ptrInput;
ptrInput = (char *)&input;
printf("Enter a string: ");
my_scanf(ptrInput);
puts(input);
fflush(stdin);
getchar();
}
my_scanf(char *ptrInput)
{
gets(ptrInput);
}
Thanks.