Good day!
How when displaying, using a variable, specify the maximum number of characters that the program can display?
#include <stdio.h> int main(){ char str[10]; int n = 2; fgets(str, sizeof(str), stdin); printf("%*.*s", n, n, str); return(0); } Good day!
How when displaying, using a variable, specify the maximum number of characters that the program can display?
#include <stdio.h> int main(){ char str[10]; int n = 2; fgets(str, sizeof(str), stdin); printf("%*.*s", n, n, str); return(0); } If you use the printf function for output, you can write as follows:
char s[] = "Hello"; printf( "%*.*s", 3, 3, s ); Or
int n = 3; char s[] = "Hello"; printf( "%*.*s", n, n, s ); Source: https://ru.stackoverflow.com/questions/586878/
All Articles