C - STRING

 STRING-

It is sequence of characters.

SYNTAX-

Declaration of string array

char arrayname [size];

Initialization of string array

char name[10]=“Hello BCA”;

‘H’

‘e’

‘l’

‘l’

‘o’

‘B’

‘C’

‘A’

‘\0’

0          1          2          3          4          5          6          7          8          9

char name [] = { ‘B’, ‘C’ , ‘A’ , ‘\o’ };

‘B’

‘C’

‘A’

‘\0’

0          1          2          3

EXAMPLE-

/* Program to input a name and display */

#include <string.h>

main()

{

char name[10];

printf(“Enter name “);

scanf(“%s”,&name);

printf(“My name is %s”,name);

getch();

}

Output-

Enter name Vikash

My name is Vikash

1. gets( ) –

This function is use to input a string from he keyboards. This function is available in stdio.h header file.

SYNTAX-

gets ( character array );

2. puts( ) – This function is use to display string on the screen.

SYNTAX-

puts ( string / character array );

 EXAMPLE-

/* Program of gets and puts */

#include <stdio.h>

main()

{

char name[10];

clrscr();

printf(“Enter name “);

gets(name);

puts(“\nGood day”);

puts(name);

getch();

}

Output-

Enter name Vikash

Good day Vikash

Comments

Popular posts from this blog

Courses After 12th Science

MS Office Versions List

Computer - Network Topologies