Semester : S1 and S2
Subject : Computer Programming
Year : 2018
Term : MARCH
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:13
char *Source_String = "Learn C Online";
strcpy(Destination_String,Source_String); printf("%s",
Destination_String);
Output: LearnC
Online ©) strncpy()
strncpy() is used to copy only the left most n characters from source to destination. The
Destination_String should be a variable and Source_String can either be a string constant or a variable.
Syntax: = strncpy(Destination_String, Source_String,no_of_characters); 6)
strcat() strcat() is used to concatenate two strings.
The Destination_String should be a variable and Source_String can either be a string constant or a
variable.
Syntax:
strcat(Destination_String, Source_String);
Example: char *Destination_String ="Learn ";
char *Source_String = "© Online";
strcat(Destination_String, Source_String); [2४५(
Destination_String);
char *Destination_String ="Learn"; char
*Source_String = "C Online";
strcat(Destination_String, Source_String); — puts(
Destination_String);
Output:
Learn © Online 0) strncat() ടന്ന) is used to concatenate only the leftmost ೧ characters from
source with the destination string.
The Destination_String should be a variable and Source_String can either be a string constant or a
variable.
Syntax:
strncat(Destination_String, Source_String,no_of_characters); Example:
char *Destination_String="Visit ";
char *Source_String = "Learn C Online is a great site";
strncat(Destination_String, Source_String,14); = puts(
Destination_String);
char *Destination_String="Visit ";
char *Source_String = "Learn C Online is a great site";
strncat(Destination_String, Source_String,14); = puts(
Destination_String);
Output:
Visit LearnC Online e)strcmp() strcmp() function is use two compare two strings. strcmp()
function does a case sensitive comparison between two strings. The Destination_String and
Source_String can either be a string constant or a variable.
Syntax: int strcmp(string1,
string2);
This function returns integer value after comparison.
Value returned is 0 if two strings are equal.
If the first string is alphabetically greater than the second string then, it returns a positive value.
If the first string is alphabetically less than the second string then, it returns a negative value Example:
char *string1 ="LearnC Online"; char *string2 ="LearnC Online"; _ int ret;
ret=strcmp(string1, string2); = printf("%d",ret);