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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago