C Program to print string
Simple C program to display string on the screen. To print a string we use %s.
To print string with space we use gets() function.
#include<stdio.h> int main() { char str[20]="C Basic Examples"; printf("String is: %s\n",str); return 0; }Another C program to get input from keyboard and print string
#include<stdio.h> int main() { char str[20]; printf("Enter a string: "); scanf("%s",str); printf("String is : %s",str); return 0; }C program to print string with space:
To print string with space we use gets() function.
#include<stdio.h> int main() { char str[20]; printf("Enter a string: "); gets(str); printf("String is : %s",str); return 0; }C program to print string using pointer
#include<stdio.h> int main() { char str[20]; printf("Enter a string: "); gets(str); char *ptr=str; printf("String is : %s",ptr); return 0; }