From: Hossein Mobahi <hmobahi@yahoo.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: assignment makes pointer from integer without a cast?
Date: Sun, 12 Dec 2004 17:47:57 -0800 (PST) [thread overview]
Message-ID: <20041213014757.89052.qmail@web12706.mail.yahoo.com> (raw)
In-Reply-To: <1102899159.7251.14.camel@guru.puzzled.xs4all.nl>
Patrick
Your program has a few incorrect assignments. Is
prog_ptr going to hold a string? I guess so because
you want to print program name. So "int *prog_ptr" is
wrong, use "char *prog_ptr" instead, i.e. an address
pointing to the first character of a given string.
Moreover, you do not need to use ampersand to obtain
prog_ptr's address because it is already a pointer
itself not an ordinary variable.
Eventually, you must pass a pointer to fprintf when
you use %s. So the * is incorrect (*prog_ptr returns a
character only, the first character of your string,
which is not what you want).
I'd rewrite your program as follows:
#include <stdio.h>
void usage(char *prog_ptr) /* not int* */
{
fprintf(stdout,"progname is: %s\n",prog_ptr); /* not
*prog_ptr */
}
int main(int argc, char *argv[])
{
char *prog_ptr; /* not int * */
prog_ptr = basename (argv[0]);
usage(prog_ptr); /* not &prog_ptr */
return(0);
}
--- Patrick <patrickC@puzzled.xs4all.nl> wrote:
> #include <stdio.h>
>
> void usage(int *prog_ptr)
> {
> fprintf(stdout,"progname is: %s\n",*prog_ptr);
> }
>
> int main(int argc, char *argv[])
> {
> int *prog_ptr;
> prog_ptr = basename (argv[0]);
> usage(&prog_ptr);
> return(0);
> }
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
next prev parent reply other threads:[~2004-12-13 1:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-13 0:52 assignment makes pointer from integer without a cast? Patrick
2004-12-13 1:47 ` Hossein Mobahi [this message]
2004-12-13 16:13 ` Francesco Gadaleta
2004-12-13 19:53 ` Jan-Benedict Glaw
2004-12-16 2:07 ` how to link mqueue library Ron Michael Khu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041213014757.89052.qmail@web12706.mail.yahoo.com \
--to=hmobahi@yahoo.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).