c 2b 2b char print fixed

Solutions on MaxInterview for c 2b 2b char print fixed by the best coders in the world

showing results for - "c 2b 2b char print fixed"
Mía
30 Feb 2017
1/*
2OUTPUT
3char variable value: Programming
4-----------------------------------------------------
5[%s]       |Programming|
6[%10s]     |Programming|
7[%15s]     |    Programming|
8[%-15s]    |Programming    |
9[%15.5s]   |          Progr|
10[%-15.5s]  |Progr          |
11-----------------------------------------------------
12*/
13
14// NOTE: Specifically used for char data-types (not strings)
15
16char str[]="Programming";    // Length = 11  
17
18std::cout << "[%s]       |";
19printf("%s",str);      // Display Complete String  
20std::cout << "|\n";
21
22std::cout << "[%10s]     |";
23printf("%10s",str);    // 10 < Length: Display Complete String  
24std::cout << "|\n";
25
26std::cout << "[%15s]     |";
27printf("%15s",str);    // 15 > Length: Displays Complete String with 4 spaces Alignment:Right  
28std::cout << "|\n";
29
30std::cout << "[%-15s]    |";
31printf("%-15s",str);   // Same as Above But Left Aligned
32std::cout << "|\n";
33
34std::cout << "[%15.5s]   |";
35printf("%15.5s",str);  // 15-5 = 10 spaces and show first 5 characters Align : R    
36std::cout << "|\n";
37
38std::cout << "[%-15.5s]  |";
39printf("%-15.5s",str); // 15-5 = 10 spaces and show first 5 characters Align : L  
40std::cout << "|\n";