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???
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
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer
read casting malloc.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++?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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 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; }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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).