thanx Elysia...
i dont get any error with fgets...
i use dev c++ with gcc compiler...
but i get a warning: "passing arg 1 of `fgets' from incompatible pointer type"... y???
Printable View
thanx Elysia...
i dont get any error with fgets...
i use dev c++ with gcc compiler...
but i get a warning: "passing arg 1 of `fgets' from incompatible pointer type"... y???
What's so bad about casting malloc in C? Wouldnt it be better because it will be easier to transfer your C code to C++?
Thank you laserlight.
I had saved it as .C
For .c it works.
And I thought extensions are not case sensitive.
Thanks all
read casting malloc.Quote:
What's so bad about casting malloc in C? Wouldnt it be better because it will be easier to transfer your C code to C++?
It means that you are trying to pass an argument to a function that expects a pointer of a certain type, but you are passing another type of pointer.
If we could see the fgets code, maybe we could help.
Example:
(fgets is expecting char*, not int*)Code:int x;
fgets(&x, 1, 1, f); /* passing arg 1 of `fgets' from incompatible pointer type */
Because of implicit function calls are masked (in case you forgot to include the header where malloc's prototype resides). See the FAQ for more details.
I certainly do agree with you there. I like to call it C++/C :D C code compiled with C++.
But we can't force anyone.
it shows a warning...Code:#include<stdio.h>
#include<conio.h>
main()
{
char *s[10];
fgets(s, 10, stdin);
printf("%s",s);
getch();
}
" passing arg 1 of `fgets' from incompatible pointer type "
i accept only char* as input...
In your new code example, s is an array of 10 char pointers. What you want is:
Code:#include<stdio.h>
int main()
{
char s[10];
fgets(s, 10, stdin);
printf("%s",s);
return 0;
}
Try reading the link for implicit main and get rid of it.
The problem is
Which creates an array of 10 char pointers.Code:char* s[10];
Thus passing this to fgets will result in char**.
Futher, the array has no allocates storage so you'd get a crash immediately.
And it's better to use getchar() instead of getch() (it's non-standard).