C Programming Tutorial - 1 - Print Text on the Screen





Hey Guys,


In this blog, I am going to show you how to print stuff on screen.
First Lets look at the code.

#include <stdio.h>

int main()
{
    printf("Thileban is Awesome");  {Put whatever you want to print with in double quotation mark}

    return 0;
}

This is the code for printing something on screen. Here all you have to do is just place whatever you want to print inside the quote mark which is inside the printf fuction. As a result you will see

Thileban is Awesome

this appear on the screen. 


There are more to this. For example you can add another line or you can tab inbetween and also you can make it produce a beep sound. Lets look at the codes for these things 


If you want to add another statement with this input this code

#include <stdio.h>

int main()
{
    printf("Thileban is Awesome");
    printf("Thileban is Cool");

    return 0;
}

However you will not get the second input in the new line rather you will get a result like this.

Thileban is AwesomeThileban is Cool 

This is because. You haven't included new line statement which \n

If you include it. The code will look like this. 

#include <stdio.h>

int main()
{
    printf("Thileban is Awesome\n");
    printf("Thileban is Cool");

    return 0;
}

You can see that I've added \n after the first sentence. As a result you will get
                                                                                                                                                                             Thileban is Awesome                                                                                                                                                                               
Thileban is Cool  

Now both are in seperate lines. In the same manner you can do tab. Also you can write a code to make alert sound. 

To tab you've to inculde \t as we did \n before

Here is the code for tab

#include <stdio.h>

int main()
{
    printf("Thileban is Awesome\t");
    printf("Thileban is Cool");

    return 0;
}

The display in the screen will be

Thileban is Awesome     Thileban is Cool

In the same manner to make an alert noise you've to include \a

Here's the code for that. 

#include <stdio.h>

int main()
{
    printf("Thileban is Awesome\a");
    printf("Thileban is Cool");

    return 0;
}

This will give you a beep noise. 



















Comments