0% found this document useful (0 votes)
7 views14 pages

Food Processing Technology: TOPIC:-String Function of With Suitable Example

The document discusses string functions in C programming, specifically those defined in the <string.h> library. It covers string characteristics, including null termination, and provides examples for five key string handling functions: length, copy, concatenation, comparison, and reversal. Additionally, a sample program demonstrates the use of these functions with output results.

Uploaded by

170010114038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Food Processing Technology: TOPIC:-String Function of With Suitable Example

The document discusses string functions in C programming, specifically those defined in the <string.h> library. It covers string characteristics, including null termination, and provides examples for five key string handling functions: length, copy, concatenation, comparison, and reversal. Additionally, a sample program demonstrates the use of these functions with output results.

Uploaded by

170010114038
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

FOOD PROCESSING TECHNOLOGY

TOPIC :- String Function of <string.h> with suitable example

Prepared By:
DIVYA MODHAWADIYA(170010114019)
KRISHNA PATEL(170010114032)

Submitted To:
PROF. MEHUL THAKKAR
String
• String is sequence of characters enclosed in double quotes. Normally
string is useful for storing data like name, address, city etc.
• ASCII code is internally used to represent string in memory.
• In C each string is terminated by special character called null
character is represented as ‘\0’ or NULL.
• Because of this reason, the character array must be declared one size
longer than the string required to be stored
CONT.
C O M P U T E R \0

• Here, the string stored is “COMPUTER”, which is having only 8 characters,


actually 9 character are stored because of NULL character at the end.

Char name[20];

• This line declares an array name of character of size 20. we can store any
string up to maximum length 19.
CONT.
• String is basically an array of characters, so we can initialize the string by
using the method of initializing the single dimensional array as shown
bellow.

char name[] = {‘c’, ‘o’, ‘m’, ‘p’, ‘u’, ‘t’, ‘e’, ‘r’, ‘\0’};
OR
char name[] = “COMPUTER”

When the string is written in double quotes, the NULL character is not
required, it is automatically taken.
STRING HANDLING FUNCTION
• There are five type of string handling function

1. String length
2. String copy
3. String cut
4. String comparison
5. String reverse
CONT.
1. String length

Syntax :- strlen(s)

This string is use for find the length of string s.


Example:-
I=strlen(“CP&U”);
returns string length 4 in variable I.
CONT.
2. String copy

Syntax :- strcpy(des,src)

This string is use for copies the string src to dest.


Example:-
if dest=“jay” and
src=“kay” then
strcpy(dest,src);
makes s1 = “kay”
CONT.
3. String copy

Syntax :- strcat(s1,s2)

This string is use for concate string s2 at the and of string s1.
Example:-
if s1=“jay” and
s2=“kay” then
strcat(s1,s2);
makes s1 = “jaykay”
CONT.
4. String comparison

Syntax :- strcmp(s1,s2)

This string is use for compares string s1 with s2. if both are equal, it returans 0.
if s1 alphabetically>s2, it returns positive number, otherwise returns negative
number.
Example:-
if s1=“jay” and
s2=“kay” then
strcmp(s1,s2);
returns -1 because “kay” os alphabetically greater than “jay”
CONT.
5. String reverse

Syntax :- strrev(s)

This string is use for reverse the string s, the original string is overwritten.
Example:-
if s=“jay” and
then
strrev(s);
makes s = “yaj”
Program demonstrating built-in
string function
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{

char str1[20]=“COMPUTER”;
char str2[20]=“computer”;
CONT.
clrscr();
printf(“Length of string %s=%d\n”,str1, strlen(str1));
i=strcmp(str1,str2);
If(i==0)
printf(“Two string are equal\n”);
else
printf(“Two string are not equal\n”);
printf(“Reverse of string %s is =”,lstr1);
strrev(str1);
printf(“=%s\n”,str1);
CONT.
strrev(str1);
Printf(“concate of %s and %s ”,str1,str2);
Strcat(str1,str2);
Printf(“=%s”,str1);
}

Output:
Length of string COMPUTER=8
Two string are not equal
Reverse of COMPUTER is = RETUPMOC
Concate of COMPUTER and computer= COMPUTERcomputer
T h an k yo u

You might also like