Create and use arrays of Strings - C String

C examples for String:String Array

Description

Create and use arrays of Strings

Demo Code

#include <stdio.h>

int main(void)
{
  char str[][70] =  {
              "this is a test this is a test this is a test.",
              "test test test test test.",
              "test test test test.",
                    };//from w  ww .  j  ava2 s  . c om
  unsigned int count = 0;                              // Length of a string
  unsigned int strCount = sizeof(str)/sizeof(str[0]);  // Number of strings
  printf("There are %u strings.\n", strCount);

  // find the lengths of the strings
  for(unsigned int i = 0 ; i < strCount ; ++i)
  {
    count = 0;
    while (str[i][count])
      ++count;

    printf("The string:\n    \"%s\"\n contains %u characters.\n", str[i], count);
  }
  return 0;
}

Result


Related Tutorials