DO NOT MISS

Ads

Sunday 11 December 2016

C-Programs Using Array of Strings


Collection of strings of character type is known as array of strings.

Syntax:-
Char stringarrayname [size1] [size2];
Size1= No. of strings  
Size2= No.of char in a string.

Ex:-
Char name [2] [20];

In the above example the name is a string and it contains two strings. 
Each strings contains 20 characters.

* Write a program to read and display no. of strings.


#include<stdio.h> 
#include<conio.h> 
void main() 
    { 

        char name[20][30]; 
        int n,i; 

        clrscr(); 

        printf("enter no of strings:"); 
        scanf("%d",&n); 

        printf("enter a string:"); 
        for(i=0;i<=n-1;i++) 
        scanf("%s",&name[i]); 

        printf("the no. of strings are:\n"); 
        for(i=0;i<=n-1;i++) 

        printf("%s\n",name[i]); 

        getch(); 

    }
Output:-


________________________________________________________________
________________________________________________________________




Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims