![]() |
| | #16 |
| Registered User Join Date: May 2008
Posts: 6
| 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??? |
| Rishi Kumar is offline | |
| | #17 |
| Registered User Join Date: Apr 2007 Location: Sydney, Australia
Posts: 217
| 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++? |
| 39ster is offline | |
| | #18 |
| and the hat of copycat Join Date: Sep 2007
Posts: 417
| 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 |
| stevesmithx is offline | |
| | #19 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #20 | |||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| Quote:
If we could see the fgets code, maybe we could help. Example: 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. Quote:
C code compiled with C++.But we can't force anyone.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |||
| Elysia is offline | |
| | #21 |
| Registered User Join Date: May 2008
Posts: 6
| 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... |
| Rishi Kumar is offline | |
| | #22 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| 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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #23 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| Try reading the link for implicit main and get rid of it. The problem is 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).
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Tags |
| char pointers, error, pointer input, pointers |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| seg fault at vectornew | tytelizgal | C Programming | 2 | 10-25-2008 01:22 PM |
| Converting a circulating mouse pointer to use a Potentionmeter | phoenix23 | C Programming | 16 | 10-29-2006 05:04 AM |
| newbie needs help with code | compudude86 | C Programming | 6 | 07-23-2006 08:54 PM |
| Program Crashing | Pressure | C Programming | 3 | 04-18-2005 10:28 PM |
| errors in class(urgent ) | ayesha | C++ Programming | 1 | 11-10-2001 10:14 PM |