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 101 views
1 answer 130 views
1 answer 154 views
154 views asked Dec 19, 2023 by avibootz
2 answers 190 views
1 answer 137 views
137 views asked Jun 6, 2023 by avibootz
1 answer 121 views
121 views asked May 14, 2022 by avibootz
...