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

When to java error comes   |   Php fatal error warning and notices   |   How to install java

QUOTES OF THE DAY

Wicked men obey from fear, good men from love

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER