Food Processing Technology: TOPIC:-String Function of With Suitable Example
Food Processing Technology: TOPIC:-String Function of 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
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)
Syntax :- strcpy(des,src)
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