C programming for Linux 4

In C text data type is called string. Basically it is an array of char with 0 value as the delimiter. we use the \0 char for the zero value at the end of string.
so if we have text with 11 charters, we will need char array with the size of 12 to include the terminating zero.
In the printf we are using %s  to print string.

Example of program:


start.c
=======================
#include 

int main(int argc, char *argv[]){
    char message[12] = "Hello World";

    printf("message is %s\n", message);

    printf("array 2 is %c\n", message[1]);
    return 0;
}
======================
oren@oren-computer:~/c-programming  
$ gcc  start.c -o start
oren@oren-computer:~/c-programming  
$ ./start 
message is Hello World
array 2 is e

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s