C - Put a String into a char Array

Introduction

C has no a string variable type.

It uses char array to store string.

Demo

#include <stdio.h> 

int main() /* w  w w  .  j a  v a  2s.  c om*/
{ 
      char prompt[] = "Press Enter to explode:"; //Line 5

      printf("%s",prompt); 
      getchar(); 
      return(0); 
}

Result

Line 5 creates an array of char variables.

The char array variable is named prompt, which is immediately followed by empty square brackets.

The array is assigned, via the equal sign, the text enclosed in double quotes.

The printf() statement displays the string stored in the prompt array.

The %s conversion character represents the string.

getchar() pauses the program, anticipating the Enter key press.

Related Topic