pTutorial

New way to learn C programming

C Program to print string

In this section, you can see a lot of print string c programs like using for loop, using a string specifier and also user define program where string entered through the keyboard.

C program to print string


//print string using for loop
#include <stdio.h>
#include <conio.h>
void main()
{
    char str[15] = "ptutorial";
    int l;
 
    for(l=0;l<strlen(str);l++)
    printf("%c",str[l]);
   getch();
}

Download String Program

Output of program

C program to print string

In this example, create a character type array and assign its value and execute a for loop until the string is over. %c is a format specifier that is used to print one character at a time.

C puts and gets function

#include <stdio.h>
#include <conio.h>
void main()
{   char a[30];
    printf(" Please enter a string ");
    gets(a);
    puts(" Entered string is: ");
    puts(a);
    getch();
}

In this example, gets and puts function is used to get and print value. With the help of gets function, you can enter any length string while in case of scanf function you can enter only one word at a time.

C program to print string

#include <stdio.h>
#include <conio.h>
void main()
{   char a[30];
    printf(" Please enter a string ");
    scanf("%s",a);
    printf(" entered string :%s",a);
    getch();   
}

Download String Program

See Also

How to increase upload file size in php   |   Why javascript void() will throw a javascript error   |   Contact us

QUOTES OF THE DAY

Eat to live, and not live for eat.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER