Array

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)

Read and print string in C

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

Array in Programming language

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

 

 

for loop in C language

while loop in C language

Do-while loop in C language

Gets() puts() function

printf() scanf() function

Data type in C language

Variables in C language

Operator in C language

 

C++ code to Read and print string of one dim array
C++ program to read and display characters of an array
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

23 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago