ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
It means exactly what it says. You're trying to use an integer as a pointer without a cast. We can't help you get rid of it unless you show us what the offending line of code is.
It means there is some integer is used in the code where the compiler would expect a pointer.
Please post some code where the error occurs. Your question sounds like a letter sent to a mechanic asking: "The engine of my car doesn't run. How can I fix this please?".
The code is in the function fopen(Const char *path, const char *mode), I'me trying to have the first argument of the function be supplied by another function that returns an integer, and that is where I get the error. So the question is: How do I turn an int into a pointer?
ps: sorry for the confusion :-(
Originally posted by bcf2
The code is in the function fopen(Const char *path, const char *mode), I'me trying to have the first argument of the function be supplied by another function that returns an integer
Trying to further explain what itsme86 already said:
The function prototype you posted says that the first argument should be a pointer to char ("const char *path"), which is quite different from a pointer to int!
If you even manage to get it to compiled without errors (itsme86's example may do that), you'll have a huge bug in your code you won't get away with. If you're lucky, you'll get a runtime error (segmentation fault). If not, your program will behave very bad in an unpredictable way. Best-case scenario being fopen() returning an error indicating "File not found". When fopen() the file for writing, or worse: creating, things may get really bad, especially if you run it as root (don't try!).
Originally posted by Hko
When fopen() the file for writing, or worse: creating, things may get really bad, especially if you run it as root (don't try!).
Yet another good reason not to run as root (that's one I hadn't really thought of). Such a mistake could be called a security hole, since it potentially allows the process to do stuff it shouldn't be doing.
But yeah, you definitely need to think this through. You're trying to ask fopen() to open a file with a name that is an integer? If you really want to open a file called "12345", then you should do some kind of string conversion (using sprintf() or the like) to convert that raw integer into a character string representing that number.
Originally posted by wapcaplet
Yet another good reason not to run as root (that's one I hadn't really thought of). Such a mistake could be called a security hole,
If you open a file for writing this way, it's potentionally worse than a security hole.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.