Read and print string of one dim array in C
Read and print string of one dim array in C
In this tutorial, we will discuss the concept of Read and print string of one dim array in C
In this topic, we are going to learn how to read and print elements of a one dimensional array in C programming language using loops.
In this blog, We have already discuss that “What is an array“, type of arrays and how to access it
Arrays are the special type of variables to store Multiple type of values(int, string,char, etc)under the same name in the continuous memory location. we can be easily accessed using the indices(indexes)
Here,
- C1,C2,C3,C4 and C5 represent the Character elements of the array
- 0,1,2,3,4 and 5 represent the index of the array which is used to access the array elements
- 1,2,3,4,5 and 6 represent the length of the array
Code to read and print string of one dim array
Read and print strings In an array
Printf() scanf() function
In this program, we are briefing input strings of an array and then print them using Printf() scanf() function
Program 1
#include <stdio.h> #include <stdlib.h> int main() { char str[20]; printf("Enter your name\n"); scanf("%s",str); printf("\nCheck your name\n"); printf("%s",str); getch(); return 0; }
When the above code is executed, it produces the following result
Enter your name Vannan Check your name Vannan
Printf() scanf() function – Declare Two arrays
In this program, we are briefing input two strings of an array and then print them using Printf() scanf() function using two arrays in C language
Program 2
#include <stdio.h> #include <stdlib.h> int main() { char str[20],str1[25]; printf("Enter your first name\n"); scanf("%s",str); printf("Enter your last name\n"); scanf("%s",str1); printf("\nCheck your full name\n"); printf("%s %s",str,str1); getch(); return 0; }
When the above code is executed, it produces the following result
Enter your first name Vannan Enter your last name Satha Check your full name Vannan Satha
gets() puts() function
we are briefing input strings of an array and then print them using gets() puts() function
Program 1
#include <stdio.h> #include <stdlib.h> int main() { char str[20]; printf("Enter any sentence\n"); gets(str); printf("\nYou have entered: \n"); puts(str); getch(); return 0; }
When the above code is executed, it produces the following result
Enter any sentence Hello how are you You have entered Hello how are you
Similar post
Code to read and print integers of an array in Java
Code to read and print strings of an array in Java
Code to read and print characters of an array in Java
Code to read and print integers of an array in C++
Code to read and print strings of an array in C++
Code to read and print characters of an array in C++
Code to read and print integers of an array in C
Code to read and print strings of an array in C
Suggested for you
One dimensional array in C language
One dimensional array in C++ language
Two dimension array in Java language
Two dimension array in C language
Two dimension array in C++ language
Three dimension array in Java language
Three dimension array in C language
Three dimension array in C++ language