STANDARD LIBRARY STRING FUNCTIONS:
1)strlen()
2)strcpy()
3)strcat()
4)strcmp()
1)strlen(): which tells about the length of the string means number of characters in that string.it also count the spaces.
Ex: int len1,len2;
len2=strlen("kite fly in sky");
printf("\n string=%s length=%d","kite fly in sky",len2);
output:
string=kite fly in sky=15 // with count of spaces.
2)strcpy(): This function copies the contents of one string into another.
Ex: char source[]="kamesh";
char target[20];
strcpy(target,source);
printf("\nstring=%s",source);
printf("\nstring=%s",target);
output:
source string=kamesh
target string=kamesh
3)strcat(): this function concatenates the source string at the end of the target
string.
For ex: "Ashok" and "varama" on concatenation would result into a string "Ashokvarama".
Ex: char s[]="ashok";
char t[]="varama";
strcat(t,s);
printf("\nstring=%s",t);
output:
sourcestring = Ashokvarama
4)strcmp(): This is a function which compares two strings to find out whether
they are same or different. the two strings are compared character by character until there is a
mismatch or end of one of the strings is reached, whichever occurs first.if the two strings are identical,
strcmp() returns a value zero.if they're not,it returns the numeric
difference between the ascii values of the non-matching characters.
Ex: char s1[]="jerry";
char s2[]="ferry";
int i,j,k;
i=strcmp(s1,"jerry");
j=strcmp(s1,s2);
k=strcmp(s1,"jerry boy");
printf("\n%d%d%d",i,j,k);
output:
0 4 -32
Popular Posts
-
<%@page contentType="text/html" import="java.util.*" %> <!-- http://www.roseindia.net/jsp --> ...
-
Introduction: In this exercise, you will exercise the concept of pass by reference. Please not that primitive type parameters are passed ...
-
The SQL UPDATE general syntax looks like this: UPDATE Table1 SET Column1 = Value1, Column2 = Value2 WHERE Some_Column = Some_Value The SQL U...
-
Structures Structures can be defined as a tool for handling a group of logically related data items. They are user-defined and provide a met...
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
Constructors A constructor is a special member function whose task is to initialize the objects of it's class. This is the first method ...
-
So far we’ve learnt how to select data from a database table and how to insert and update data into a database table. Now it’s time to learn...
-
Introduction: In this exercise, you will exercise the concept scope variable. Steps to follow: 1. Write ScopeOfVariable.java as shown in Cod...
-
The SQL INSERT INTO syntax has 2 main forms and the result of either of them is adding a new row into the database table. The first syntax f...
No comments:
Post a Comment