linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Sobotta <mayday@gmx.net>
To: Krishna Mohan <gkmohan@rocsys.com>
Cc: Linux c programming list <linux-c-programming@vger.kernel.org>
Subject: Re: scanf with pointers as arguments
Date: Wed, 17 Nov 2004 07:20:22 +0100	[thread overview]
Message-ID: <200411170720.22222.mayday@gmx.net> (raw)
In-Reply-To: <1100670616.1157.15.camel@KrishnaMohan>

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

  reply	other threads:[~2004-11-17  6:20 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 [this message]
2004-11-17  8:56   ` Krishna Mohan

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=200411170720.22222.mayday@gmx.net \
    --to=mayday@gmx.net \
    --cc=gkmohan@rocsys.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).