Deitel & Deitel, C How to Program 6th Edition, Exercise 9.12 (Displaying a String in a Field)

// 9.12 Displaying a String in a Field

#include <stdio.h>

int main() {
int length; //letter count
char string[20];
printf("Enter a word: ");
scanf("%s%n", string, &length); //determining the length of string
printf("%*s", 2*length, string); //printing the string using twice the length as the field width

printf("\n\n\n");
return 0;
}

OUTPUT

Enter a word: Ugur
    Ugur


Press any key to continue . . .

Comments

Popular posts from this blog

Deitel & Deitel, C How to Program 6th Edition, Exercise 6.23 (Turtle Graphics)

Deitel & Deitel, C How to Program 6th Edition, Exercise 6.22 (Total Sales)

Deitel & Deitel, C How to Program 6th Edition, Exercise 5.47 (Craps Game Modification)