undeclared identifier

I get a dialog box that says abort retry or ignore My
problem is when i compile it gives my that error can someone help me
/* Fig 9.7: fig09_07.c */
/* Using the p, n, and % conversion specifiers */
include<stdio.h>

int main ( )
{
int *ptr; /* define pointer to int */
int x = 12345; /* initialize int x */
int y; /* define int y */

ptr = &x; /* assign address of x to ptr */
printf( "The value of ptr is %p\n", ptr );
printf( "The address of x is %p\n\n", &x );

printf( "Total characters printed on this line:%n", &y );
printf( " %d\n\n\n", y );

y = printf( "This line has 28 characters\n" );
printf( "%d characters were printed\n\n", y );

printf( "Printing a %% in a format control string\n" );

return 0; /* indicates successful termination */

} /* end main */
Last edited on
printf( "Total characters printed on this line:%n", &y );
y is uninitialized at this point.
It's working perfectly fine in my system. I used VC++.
@helios: %n assigns value to the variable y, so we do not need to explicitly do it.
Last edited on
No, it doesn't. That's scanf().
Last edited on
closed account (z05DSL3A)
I can not be certain because the OP has not given any info on His system/dev environment but from the sound of it He is getting a debug assertion failed because VC dose not have the 'n' specifier enabled by default. If this is the case then the OP will need to add _set_printf_count_output(1); at the start of main:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>

int main ( )
{
    _set_printf_count_output(1);

    int *ptr; /* define pointer to int */ 
    int x = 12345; /* initialize int x */ 
    int y; /* define int y */ 

    ptr = &x; /* assign address of x to ptr */ 
    printf( "The value of ptr is %p\n", ptr );
    printf( "The address of x is %p\n\n", &x );

    printf( "Total characters printed on this line:%n", &y);
    printf( " %d\n\n\n", y );

    y = printf( "This line has 28 characters\n" );
    printf( "%d characters were printed\n\n", y );

    printf( "Printing a %% in a format control string\n" );

    return 0; /* indicates successful termination */ 

} /* end main */


helios, %n will indeed assigns the printf count to the variable y.
Last edited on
Topic archived. No new replies allowed.