C examples for String:String Console Input
Align each letter count with the end of the corresponding name.
#include <stdio.h> #include <string.h> int main(void) { char first_name[20]; char last_name[20]; printf("Enter your first and last name: "); scanf("%s %s", first_name, last_name); printf("\n");/*from w ww .j av a2 s . co m*/ printf("%s %s\n", first_name, last_name); printf("%*lu %*lu\n", // right justified (int) strlen(first_name), strlen(first_name), (int) strlen(last_name), strlen(last_name)); printf("\n"); printf("%s %s\n", first_name, last_name); printf("%-*lu %-*lu\n", // left justified (int) strlen(first_name), strlen(first_name), (int) strlen(last_name), strlen(last_name)); printf("\n"); return 0; }