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???
This is a discussion on char pointers in C within the C Programming forums, part of the General Programming Boards category; thanx Elysia... i dont get any error with fgets... i use dev c++ with gcc compiler... but i get a ...
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++?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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++/CC code compiled with C++.
But we can't force anyone.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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; }
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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).
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^