STRING
C LANGUAGE
Presented by
CS 2304040 –Tanvir
CS 2304041 -Ashik
CS 2304043 -Rafy
CS 2304046 –Tosikul
CS 2304055 -Tofiq
CS 2304056 -Shreya
CS 2304057 -Ashik
What is string…..
String-A sequential collection of characters
or a character Array terminated by a null
character(‘\0’)
Header file of string…
#include<stdio.h>
#include<string.h>
`<string.h>` is a header file in the C
programming language that provides a set of
functions for manipulating strings.
Contents
Declaration
variable declaration
input/output and format specifiers
Standard library functions
String codes.
String variable
declaration
Char name[]=“rafy”; char
random[]={‘a’,’1’,’*’,’y’};
Printf(“%s”, name); printf(“%s”, random);
‘r’ ‘a’ ‘f’ ‘y’ ‘\ ‘a’ ‘1’ ‘*’ ‘y’ ‘\0’
0’
String input output
Input function : scanf / gets / fgets
Example
scanf(“%s”, name); // input a single word
scanf(“%[^\n]s”, name); // input a sentence
gets(name); // input a single word
fgets(name,sizeof(name),stdin); // input a sentence
Output function: printf/puts
printf(“name is= %s”, name);
puts(name);
Format Specifier
%s
Standard Library
Functions<string.h>
strlen : returns length of the string
int strlen (const char *)
strcpy : copy one string into another
char strcpy (char *, const char *)
strcpy(s1,s2);
strcat : concantenates (combines) two strings
char strcat (char *, const char *)
strcat(s1,s2);
strcmp : compare two strings
int strcmp (const char *, const char *)
res = strcmp (s1,s2);
String
length(strlen)
String copy(strcpy)
String concantenates (strcat
)
String compare(strcmp)
Thank You
Everyone…..