Use scanf() with %n Specifier - C Language Basics

C examples for Language Basics:scanf

Introduction

scanf( ) with %n stores the number of characters read from the input up to where the %n was encountered into the integer variable pointed to by the corresponding argument.

Demo Code


#include <stdio.h>

int main(void)
{
   char *p;//from w  ww  .j  av  a  2  s  . c  o m
   int n;

   printf("Enter an address: ");

   scanf("%p %n", &p, &n);

   printf("%d", n);

   return 0;
}

Result


Related Tutorials