String in C Programming

What is string?

String is a collection of symbols. String is a set of symbols. String is also called set of characters.

We can use alphabets,digits and special characters in string.
Alphabets:- A, B, ….., Y, Z a, b, ……, y, z Digits :- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special symbols :- ~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { } [ ] : ; " ' < > , . ? /

What is string?

String Without Size

\0 represents NULL.

"string.h" header file include in your program.

%s placeholder is used to print value of string.

Syntax

char variableName[ ] ={'symbol-1', 'symbol-2',........,'\0'};

example:
char str[ ] = {'c', 'o', 'm', 's', 'y', 's', 'a', 'p','p', '.', 'c', 'o', 'm', '\0'};

See Output

String With Size

See Output

Print Every Character Of String

See Output

First way of string variable declaration

If a value is given in double quotes ("") it is called string.

Syntax

char variableName[size] = value;

example:
char str[size] = "HELLO WORLD";


Second way of string variable declaration

Syntax

char variableName[size];

example:
char str[size];

See Output

gets()

gets() is a predefined function. It is used to read string value from user.

See Output

puts()

puts() function is predefined function. It is used to print value of string.

See Output

strlen()

It is predefined function. It returns length of string.

See Output

strcpy()

It is a predefined function.

It is used to copy from source variable and paste in destination variable.

Syntax

strcpy(destination, source);

See Output

strcat()

It is used to concatenate strings.

Syntax

strcat(string_1,string_2);

See Output

strcmp()

It is a predefined function. It check two string is equal or not. If both strings are equal then it returns 0.

Syntax

strcmp(string_1,string_2);

See Output

strrev()

It prints reverse of string.

See Output

strlwr()

It converts uppercase string into lowercase.

See Output

strupr()

It converts lowercase string into uppercase.

See Output

About Us

Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.

Services

Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.


Terms of Use

comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.

Privacy policy

comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.


Sitemap

sitemap

copyright © 2023