Poornima College of Engineering: Sting, String Functions
Poornima College of Engineering: Sting, String Functions
Poornima College of Engineering: Sting, String Functions
Engineering
Sting, string functions
Vishal Choudhary
Deptt. Of CS
Session outline
String
String program
What is string
Sequence of character is called string
In C “the sequence of character enclosed in
char s[5];
HelloWorld
strlen(str1) : 10
Read String from the user
#include <stdio.h>
int main()
{
char name[15];
gets(name); //reads a string
puts(name); //displays a string
return 0;
}
1. Which among the following is Copying function?
a) memcpy()
b) strcopy()
c) memcopy()
d) strxcpy()
A
-1
.
B
1
.
C
0
.
D
Yes
.
How will you print \n on the screen?
printf("\n");
echo "\\n";
printf('\n');
printf("\\n");
What is output?
#include <stdio.h>
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
important library functions are:
strncmp(str1, str2, n) :
It returns 0 if the first n characters of str1 is equal to
the first n characters of str2, less than 0 if str1 <
str2, and greater than 0 if str1 > str2.
strncpy(str1, str2, n)
This function is used to copy a string from another
string. Copies the first n characters of str2 to str1
strchr(str1, c):
A character such as 'd' is not a string and it is indicated by single quotation marks.
'C' provides standard library functions to manipulate strings in a program. String manipulators
There are different input and output string functions, each one among them has its features.
Don't forget to include the string library to work with its functions