Home C-tutorials C Array of String

Related Tutorials


 
 

Share on Google+Share on Google+

C Array of String

Advertisement
A String is an array of char objects. An array of string can be declared and handled like a 2d(two dimensional) arrays.

C Array of String

     

In this section you will learn how to create an array of string in C.

A String is an array of char objects. An array of string can be declared and handled like a 2d(two dimensional) arrays. You can see in the given example that we have declare a 2 dimensional character array consisting of three 'rows' and twelve 'columns'. The array is initialized with three character strings. In C, a format specifier %s is used with the printf to print the string.

Here is the code:

ARRAYSTR.C

 

 


#include <stdio.h>
#include <conio.h>
void main() {
  clrscr();
  char arr[3][12]"Rose""India""technologies" };
  printf("Array of String is = %s,%s,%s\n", arr[0], arr[1], arr[2]);
  getch();
}

Output will be displayed as:

ARRAYSTR.EXE

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2009

Related Tutorials

Discuss: C Array of String   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:5
sukhendra
September 20, 2011
c array of string

i am feel so lucky
milad
October 10, 2011
C++

many thanks it is verey good could you please show me how i can create a folder for multyexecution. i have done this MakeDir(path) it is works ok but i need eatch time i run program, the program will create a new folder. for example first one is: test1, 2sd one test2 and so on. many thanks
Guus de leeuw
November 4, 2011
String overflow error

use arr[3][20] instead of arr[3][12] because strlen("technologies") == 12 !!
rohan
March 1, 2013
web page designing

hi
Pedro
October 5, 2012
Forgot the null char

I think you forgot the \0 (null terminated string). your array should have the size 13 and not 12. "technologies\0"
DMCA.com