WELCOME TO MY PRESENTATION
AbdullahAlYeamin
Maruf
ID: 173-35-256
String in C programming Language
Introducing String
In C programming, array of characters is called a string.
• A string is terminated by a null character /0.
For example:
Declaration
Before we actually work with strings, we need to declare them first.
• Strings are declared in a similar manner as arrays. Only difference
is that, strings are
of char type.
• char s[5];
s[0] s[1] s[2] s[3] s[4]
Initiation of String
• In C, string can be initialized in a number of different ways.
• For convenience and ease, both initialization and declaration
are done in the same step.
• char c[] = "abcde";
OR
• char c[5] = "abcde";
c[0] c[1] c[2] c[3] c[4]
a b c d e
Simple String Program
#include <stdio.h>
int main()
{
char name[20];
printf("Enter name: ");
scanf("%s", name);
printf("Your name is %s.n", name);
return 0;
}
String Functions
strlen()
strcmp()
strcat()
strcpy()
strupr()
strlwr()
strrev()
NB: Before using these function using first #include<string.h> herder file.
Using strlen() function
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[12] = "Hello";
int len ;
len = strlen(str1);
printf("The length of string: %dn", len );
return 0;
}
Using strcpy() function
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[12] = "Hello";
char str3[12];
strcpy(str3, str1);
printf("strcpy( str3, str1) : %sn", str3 );
return 0;
}
Using strcat() function
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[12] = "Hello";
char str2[12] = " World";
strcat( str1, str2);
printf("strcat( str1, str2): %sn", str1 );
return 0;
}
Thank You Everyone.

String C Programming