How can I make a blank space - example three spaces - before printing sth in C? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I make a blank space - example three spaces - before printing sth in C?

C language

29th Jun 2018, 7:35 PM
Retag Tarek
Retag Tarek - avatar
6 Answers
+ 4
I will post two programs, one handwritten(basic space program) and other as post(advance space program). So you can select your choice:- This is a basic program to space:- /* Function to n space.Create any number of space*/ void create_space(int n) { int i=0; for(i=1;i<=n;++i) printf(" "); } //driver program to function main() { create_space(3); printf("There are 3 spaces before this\n\n"); create_space(5); printf("There are 5 spaces before this\n\n"); } Important Big Note:- Dont use '\n' New linefeed before the word or printf because it will skip the spaces and you won't get your desired output.Put it at the end of word/string or in the printf. BELOW GIVEN IS AN ADVANCE PROGRAM:- If you want advance program to spaces and formatting,then check this code out https://code.sololearn.com/crtkXMM7zhqY/?ref=app
1st Jul 2018, 10:00 PM
D-Key
D-Key - avatar
+ 3
Jist add spaces with the spacebar Retag Tarek I have created an exaple code here: https://code.sololearn.com/cYK6U1rY2J3S/?ref=app
29th Jun 2018, 7:45 PM
Agent
Agent - avatar
+ 3
sorry i dont know any other way
29th Jun 2018, 7:54 PM
Agent
Agent - avatar
+ 1
Agent Thank you But I am making a for loop so this doesn't work for me it make space between the context itself so is there any other way? And can I make the number of spaces varies every time the loop work?
29th Jun 2018, 7:52 PM
Retag Tarek
Retag Tarek - avatar
+ 1
Agent never mind, Thank you 😄
29th Jun 2018, 7:57 PM
Retag Tarek
Retag Tarek - avatar
0
for known number of spaces there's a trick: printf("%3shello world\n","");
13th Jul 2018, 10:43 AM
Микола Федосєєв
Микола Федосєєв - avatar