Output JBL in Block Letters with C Programming

Click For Summary
SUMMARY

The discussion focuses on creating a C program to output the initials "JBL" in block letters. The initial code provided by the user fails to format correctly due to missing newline characters. The solution involves adding the newline character '\n' within the printf statements to ensure proper line breaks. Additionally, the user learns that using tab characters can affect spacing, leading to misalignment in the output.

PREREQUISITES
  • Basic understanding of C programming syntax
  • Familiarity with the printf function in C
  • Knowledge of string formatting and escape characters
  • Experience with debugging output formatting issues
NEXT STEPS
  • Learn about C programming escape sequences, including '\n' and '\t'
  • Explore advanced formatting options with printf in C
  • Investigate using a single printf statement for multi-line output
  • Practice debugging common formatting issues in C programs
USEFUL FOR

Beginner C programmers, students learning about output formatting, and anyone interested in improving their coding skills in C.

jaydnul
Messages
558
Reaction score
15
All i have to do is write a program that will output my initials (JBL) in block letters.

This is what i have done:

Code:
#include <stdio.h>
void main()
{
printf("	 JJJJJJ  BBBBBBBB  LLL");
printf("	   JJ     BB    BB    LLL");
printf("	   JJ    BBBBBBB    LLL");
printf("	   JJ    BB    BB     LLL");
printf("      JJ JJ     BB    BB    LLLLLLLL");
printf("	JJJJJ    BBBBBBBB  LLLLLLLL");
}

Now this is wrong of course. When i execute, it will print the top line with the correct number of spaces, but after the first LLL it just goes wack. I assume it is because i am not telling it when to start a new line, right? If so, how do i do that? Also, could i just use 1 printf statement instead of 6?
Thanks
 
Last edited by a moderator:
Physics news on Phys.org
The newline character '\n' should be added inside the "" of the printf string:

printf(" This is a line of text.\n");
 
ahh perfect. Thank you. another problem i was having was i didn't know tab would act as a single space, so it was printing all messed up. Got it now. Thanks SteamKing
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
9
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
Replies
7
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 21 ·
Replies
21
Views
4K