From: Krishna Mohan <gkmohan@rocsys.com>
To: Benjamin Sobotta <mayday@gmx.net>
Cc: Linux c programming list <linux-c-programming@vger.kernel.org>
Subject: Re: scanf with pointers as arguments
Date: 17 Nov 2004 14:26:04 +0530 [thread overview]
Message-ID: <1100681765.1157.18.camel@KrishnaMohan> (raw)
In-Reply-To: <200411170720.22222.mayday@gmx.net>
Hi
thanqs alot benjamin sobotta.
it's working fine. i need to give exact pointer type.
Regards
krishna mohan
On Wed, 2004-11-17 at 11:50, Benjamin Sobotta wrote:
> Hi!
>
> Will the problem is not the pointer but the type. Since you use short you have
> to adjust that.
> That works for me:
>
> #include<stdio.h>
>
> int main()
> {
> int i,*iptr = &i;
> short int s,*shptr = &s;
> printf("enter 2 values:\n");
> scanf("%d %hd",iptr,shptr);
> printf("%d %hd\n",*iptr,*shptr);
> printf("%d %hd\n",i,s);
>
> return 0;
> }
>
>
>
> On Wednesday 17 November 2004 06:50, Krishna Mohan wrote:
> > Hi
> > Can anybody plz tell me what's wrong with this code!
> > I am getting SEGMENTATION FAULT. ofcourse, if i use &i, &s as arguments
> > in scanf, it's work fine as usual. can't i use pointers which hold the
> > address of i and s. plz clarify this. THANKS IN ADVANCE.
> >
> > int i,*iptr = &i;
> > short s,*shptr = &s;
> > printf("enter 2 values:\n");
> > scanf("%d %d",iptr,shptr);
> > printf("%d %d\n",*iptr,*shptr);
> > printf("%d %d\n",i,s);
> >
> >
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe
> > linux-c-programming" in the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2004-11-17 8:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-17 5:50 scanf with pointers as arguments Krishna Mohan
2004-11-17 6:20 ` Benjamin Sobotta
2004-11-17 8:56 ` Krishna Mohan [this message]
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=1100681765.1157.18.camel@KrishnaMohan \
--to=gkmohan@rocsys.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=mayday@gmx.net \
/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).