use char array as string : Char Array « Data Type « C++






use char array as string

   
#include <stdio.h>

int main( )
{
 char        szmode1[4],             /* car   */
             szmode2[6];             /* plane */
 static char szmode3[5] = "ship";    /* ship  */

 szmode1[0] = 'c';
 szmode1[1] = 'a';
 szmode1[2] = 'r';
 szmode1[3] = '\0';

 printf("\n\n\tPlease enter the mode > plane ");
 scanf("%s",szmode2);

 printf("%s\n",szmode1);
 printf("%s\n",szmode2);
 printf("%s\n",szmode3);

 return(0);
}
  
    
    
  








Related examples in the same category

1.use getline to read char array based string
2.Use cin.getline to read a char array based string
3.Char array and char pointer
4.Use new operator to allocate memory for char array