How to use %n in printf() to count the number of characters before the occurrence of %n in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    int x;
    
    printf("abcd!%nefg\n", &x);
  
    printf("Count: %d", x);
  
    return 0;
}




/*
run:

abcd!efg
Count: 5

*/

 



answered Jun 8, 2023 by avibootz

Related questions

1 answer 95 views
1 answer 121 views
1 answer 144 views
144 views asked Dec 19, 2023 by avibootz
2 answers 182 views
1 answer 132 views
132 views asked Jun 6, 2023 by avibootz
1 answer 118 views
118 views asked May 14, 2022 by avibootz
...