0% found this document useful (0 votes)
39 views3 pages

Strings in C Lan

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Strings in C Lan

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

STRING

What is String and String related function?


What is a null character? What are its uses in strings?
Explain the following string handling functions with examples: (i) strcpy( ) (ii) strcat( ) (iii) strrev( ) (iv) strlen
Explain different string handling functions available in C language.
What are the differences between an array and string?
Define string. How string is declared and initialized?
Mention the various String Manipulation Functions in C.
Define string. Explain about string operations with examples.
Explain the following string handling functions: (i)strcpy() (ii)strlen() (iii)strcat() (iv)strcmp()
Develop a program to implement string operations by using string handling functions.
Illustrate the string operations :i) Copying the string ii) Reversing the string iii) Update the Characters in string iv)Finding the string
length
Write the logic for finding the string length with out a predefined function.
Develop a program to append the one string to another string without using predefined functions.
What is string palindrome? Develop a program to check whether the given string is palindrome or not.
Develop a program that performs string concatenation and string reverse without predefined functions.
Develop a program to find the length of the string with out using predefined functions.

The group of alpha numeric characters which are enclosed within double quotes (“ ”) are called Strings,.
• Every String is terminated with NULL (‘\0’) character.
• Character array is also called string
• It is not compulsory to write ‘\0’ character at the end of the string, the compiler automatically puts ‘\0’ at the end of string
of a character array.
Declaration syntax: char stringname[size];
Example: char name[30];
Initialization syntax: char stringname[size]=” string value “;
Ex: Char name[30] = “KIET”
K I E T \0

String handling Functions are:


1. strlen()
2. strcpy()
3. strcat()
4. strrev()
5. strcmp()
6. strlwr()
7. strupr()

1.STRLEN():The function is used to count the number of characters in the given string
SYNTAX: Len=strlen(“text/string”);
EXAMPLE:
void main()
{
Int l;
char s[100];
printf(“Enter the string”);
gets(s);
l=strlen(s);
printf(“length of string s : %d”, l);
}

2. STRCPY():The function copies the content of one string to other string.


DECLARATION SYNTAX: strcpy(dest string, source string);
EXAMPLE:
void main()
{
char a[100],b[100];
printf(“Enter string a”);
gets(a);
strcpy(b,a);
printf(“Copied string is: %s”,b);
}

3.STRCAT():Concatenation of strings second string is appended to first string.


SYNTAX: strcat(text1,text2);
EXAMPLE:
void main()
{
char a[100],b[100];
printf(“Enter string a”);
gets(a);
printf(“Enter string b”);
gets(b);
strcat(a,b);
printf(“Final string is %s”,a;)
}
4. STRREV():It is used to reverse the given string.
SYNTAX: strrev(string);
EXAMPLE:
void main()
{
char a[100];
printf(“Enter string to reverse”);
gets(a);
strrev(a);
printf(“Reversed string is %s”,a);
}

5. STRCMP():The function is used to compare two strings i.e. equal or not equal.
SYNTAX: strcmp(str1,str2);
EXAMPLE:
void main()
{
char a[100],b[100];
int cmp;
printf(“Enter string a”);
gets(a);
printf(“Enter string b”);
gets(b);
cmp= strcmp(a,b);
if (cmp>0)
{
printf(“b is less than a”);
}
}

6 .STRLWR():This function is used to convert a given string into lower case.


SYNTAX: strlwr(string);
EXAMPLE:
Void main()
{
Char a[100];
Printf(“enter the string”);
gets(a);
Printf(“%s”,strlwr(a));
}
7.STRUPR() :This function is used to convert a given string into upper case.
SYNTAX: strupr(string);
EXAMPLE:
Void main()
{
Char a[100];
Printf(“enter the string”);
gets(a);
printf(“%s”,strupr(a));
}
Write a C program to verify given a string for its palindrome or not

#include <stdio.h>
#include <conio.h>

void main()
{
char st[20];
int i,j,l,c;

printf("Enter string:");
scanf("%s",&st);
l=0;
for(i=0;st[i]!='\0';i++) // finding length
l=l+1

for(i=0,j=l-1,c=0;st[i] !='\0';i++,j--)
{
if ( st[i] == st[j] )
c++;
}

if( c == l )
printf("\nGiven string is palindrome ");
else
printf("\nGiven string is not palindrome ");
}

You might also like