!!!!
""""
Strings/Character Array: in C language the group of characters,
digits and symbols enclosed within quotation marks are called
string.
- The string always declared as character array.
- In other word character array are called string.
- Every string is terminated with ‘0’ (NULL) character.
- The null character is a byte with all bits at logic zero.
- For example: char name[ ]={‘S’,’A’,’N’,’T’,’T’,’O’,’S’,’H’};
- Each character of the string occupies 1 byte of memory.
- The last character is always‘0’.
- It is not compulsory to write, because the compiler
automatically put’0’ at the end of character array or string.
- The character array stored in contiguous memory locations
- For example Memory map of string
1001 1001 1002 1003 1004 1005 1006 1007
Declaration and initialization of string:
Char name [ ] =”SANTOSH”;
Q. Write a program to display string
Void main ()
{
Char name [6] = {‘J’,’A’,’C’,’K’,’Y’};
Clrscr ();
Printf (“Nam=%s”, name);
}
Output: JACKY
S A N T O S H 0
!!!!
""""
Important Note: it character array no need of write & in scanf
statement because as we know that string is a collection of
character, which is also called character array. The character are
arranged or stored in contiguous memory location, so no need of
address to store the string.
How to read a character
- To read a character use the following function
- char getch()
- char getche()
Difference between getch() and getche():
- In case of getch() the input data does not visible on screen.
- In case of getche() the input data visible on screen.
How to display a character:
- To display a character use following function.
- putch() void putch(data)
How to read a string:
- To read a string use following function
- gets(): whole string is accepted
How to display a string:
- puts ( ): it is used to display a string.
Example:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10],i;
clrscr();
printf("Enter a string");
gets(a);// to read a string
!!!!
""""
puts(a);// it is used to display a string
printf("%s",a);//display the string
for(i=0;a[i]!='0';i++)
printf("%c",a[i]);
getch();
}
Output: Enter a string: JACKY
JACKY
JACKY JACKY
Explanation: ill print three times because for gets (),puts(),and
printf();
Standard String Functions:
Function Description
Strlen() Determine length of string
Strcpy() copies a string from source to destination
Strcmp() a) compare character of two string (function
determine between small and big)
b) if the two string equal it return zero otherwise it
return nonzero.
c) it the ASCII value of two string.
d) it stop when either end of string is reached or the
corresponding character are not same.
Strcat() append source string to destination string.
Strrev() reverse all character of a string.
Strlwr() it is used to convert a string to lower case.
Tolower() it is used to covert a character to lower case
Strupr() it is used to convert string to upper case.
Touppper() it is used to convert a character to upper case
!!!!
""""
Program: WAP to find the length of string Strlen()
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char p[50];
int len;
clrscr();
printf("Enter a Text:n");
gets(p);
len=strlen(p);
printf("length of string=%d",len);
getch();
}
Program: WAP to find the length of string without using Strlen()
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char p[50];
int len=0,i;
clrscr();
printf("Enter a string:n");
gets(p);
for(i=0;p[i]!='0';i++)
len++;
printf("length of string %s=%d",p,len);
getch();
}
!!!!
""""
Program: WAP to input a string then copy one string to another
string using strcpy ().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
clrscr();
printf("Enter a string:n");
gets(a);
strcpy(b,a);
printf("string %s is copy %s",a,b);
getch();
}
Program: WAP to input a string then copy one string to another
string without using strcpy ().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
int i;
clrscr();
printf("Enter a string:n");
gets(a);
for(i=0;a[i]!='0';i++)
b[i]=a[i];
b[i]='0';
printf("string %s is copy %s",a,b);
getch();
}
!!!!
""""
Program: WAP to input two string then joined it using strcat()
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
int i;
clrscr();
printf("Enter ist string:n");
gets(a);
printf("Enter 2nd string:n");
gets(b);
strcat(a,b);
printf("%s",a);
getch();
}
Program: WAP to input two string then compare it using
strcmp().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
clrscr();
printf("n Enter 1st string");
gets(a);
printf("Enter 2nd string");
gets(b);
if(strcmp(a,b)==0)
printf("equal");
else
!!!!
""""
printf("not equal");
getch();
}
Program: WAP to input two string then compare it without
using strcmp().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
int i=0;
clrscr();
printf("n Enter 1st string");
gets(a);
printf("Enter 2nd string");
gets(b);
while(a[i]!='0'&&b[i]!='0'&&a[i]==b[i])
i++;
if(a[i]==b[i])
printf("equal");
else
printf("not equal");
getch();
}
Program: WAP to input a string then reverse it using strrev().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
clrscr();
!!!!
""""
printf("n Enter 1st string");
gets(a);
strrev(a);
printf("n %s",a);
getch();
}
Program: WAP to input a string then reverse it without using
strrev().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50];
int i,k=0;
clrscr();
printf("n Enter a string");
gets(a);
for(i=strlen(a)-1;i>=0;i--)
b[k++]=a[i];
b[k]='0';
printf("n %s",b);
getch();
}
Program: WAP to input a string then convert it into lower case
using strrev().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
clrscr();
!!!!
""""
printf("n Enter a string");
gets(a);
strlwr(a);
printf("n %s",a);
getch();
}
Program: WAP to input a string then convert it into lower case
without using strlwr().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
int i;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;a[i]!='0';i++)
{
if(a[i]>=65&&a[i]<=90)
a[i]=a[i]+32;
}
printf("n %s",a);
getch();
}
Program: WAP to input a string then convert it into lower case
using tolower().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
!!!!
""""
char a[50];
int i;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;a[i]!='0';i++)
{
if(a[i]>=65&&a[i]<=90)
a[i]=tolower a[i];
}
printf("n %s",a);
getch();
}
Program: WAP to input a string then convert it into lower case
using strupr ().
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
clrscr();
printf("n Enter a string");
gets(a);
strupr(a);
printf("n %s",a);
getch();
}
Program: WAP to input a string then convert it into lower case
without using strupr ().
#include<stdio.h>
#include<conio.h>
#include<string.h>
!!!!
""""
void main()
{
char a[50];
int i;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;a[i]!='0';i++)
{
if(a[i]>=97&&a[i]<=122)
a[i]=a[i]-32;
}
printf("n %s",a);
getch();
}
Program: WAP to input a string then find out occurrence of
each character.
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char a[50];
int i,k,j,c;
clrscr();
printf("Enter a string");
gets(a);
for(i=0;i<strlen(a);i++)
{
c=1;
for(j=i+1;j<strlen(a);j++)
{
if(a[i]==a[j])
!!!!
""""
{
c++;
for(k=j;k<strlen(a);k++)
a[k]=a[k+1];
j--;
}
}
printf("n%c is print %d times",a[i],c);
}
getch();
}
Program: WAP to input a string then find out how many words
are there.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
int w=0,i=0;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;i<strlen(a);i++)
{
if(a[i]==32)
w++;
}
printf("n no of words=%d",w);
getch();
}
!!!!
""""
Program: WAP to input a string then find out how many digits,
space, alphabets, special symbols.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
int i,p=0,d=0,s=0,sp=0;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;i<strlen(a);i++)
{
if(a[i]>=65&&a[i]<=90||a[i]>=97&&a[i]<=122)
p++;
else if(a[i]>=48&&a[i]<257)
d++;
else if(a[i]==32)
s++;
else
sp++;
}
printf("n no of alphabets=%d",p);
printf("n no of digits=%d",d);
printf("n no of space=%d",s);
printf("n no of special symbol=%d",sp);
getch();
}
!!!!
""""
Program: WAP to input a string then find out how many vowels
are there.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
int i,v=0;
clrscr();
printf("n Enter a string");
gets(a);
for(i=0;a[i]!='0';i++)
{
if(a[i]=='a'||a[i]=='A'||
a[i]=='e'||a[i]=='E'||
a[i]=='i'||a[i]=='I'||
a[i]=='o'||a[i]=='O'||
a[i]=='u'||a[i]=='U')
v++;
}
printf("n Total no of vowes=%d",v);
getch();
}
Program: WAP to input a string then convert into lower case.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50];
int i;
clrscr();
!!!!
""""
printf("n Enter a string");
gets(a);
for(i=0;a[i]!='0';i++)
{
if(a[i]>=65&&a[i]<=90)
a[i]=tolower a[i];
}
printf("n %s",a);
getch();
}
Program: WAP to input a string then check string is palindrome
or not.
#include<stdio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the string to check if it is a palindromen");
gets(a);
strcpy(b,a);
strrev(b);
if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.n");
else
printf("Entered string is not a palindrome.n");
return 0;
}
!!!!
""""
Program: WAP to input a string then construct a structure.
#include<stdio.h>
#include<string.h>
main()
{
char string[100];
int c, k, length;
printf("Enter a stringn");
gets(string);
length = strlen(string);
for ( c = 0 ; c < length ; c++ )
{
for( k = 0 ; k <= c ; k++ )
{
printf("%c", string[k]);
}
printf("n");
}
return 0;
}
Program: WAP to input a string then sorting of string .
#include<stdio.h>
int main(){
int i,j,n;
char str[20][20],temp[20];
puts("Enter the no. of string to be sorted");
scanf("%d",&n);
for(i=0;i<=n;i++)
gets(str[i]);
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
!!!!
""""
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("The sorted stringn");
for(i=0;i<=n;i++)
puts(str[i]);
return 0;
}
Program: WAP to input a string then check string is palindrome
or not.
#include<stdio.h>
#include<string.h>
main()
{
char a[100];
int c, k, length;
printf("Enter a stringn");
gets(string);
length = strlen(string);
for ( c = length-1; c >=0 ; c-- )
{
b[k]=’0’;
b[k++]=a[i];
}
If(b[i]=a[i])
Printf(“String is palindrome”);
}
else
printf("not a palindrome”);
getch();
!!!!
""""
Program: WAP to input a string then input a character and
check occurrence of character.
#include<stdio.h>
#include<string.h>
main()
{
char a[100],ch;
int i,c=0;
printf("Enter a stringn");
gets(string);
printf("Enter a stringn");
ch=getch();
for ( i=0;i<strlen(a);i++)
{
If[a[i]==ch)
C++;
}
Printf(“Total no of %c in string %d”,c);
}
getch();
}

More Related Content

DOCX
C lab manaual
PPTX
Programming ppt files (final)
PDF
8 arrays and pointers
DOCX
Practical File of C Language
PDF
C Prog. - Strings (Updated)
PDF
C Prog. - Structures
PDF
C Prog - Strings
PPTX
Lecture 1 string functions
C lab manaual
Programming ppt files (final)
8 arrays and pointers
Practical File of C Language
C Prog. - Strings (Updated)
C Prog. - Structures
C Prog - Strings
Lecture 1 string functions

What's hot (20)

PPT
All important c programby makhan kumbhkar
DOC
Basic c programs updated on 31.8.2020
DOCX
Best C Programming Solution
DOCX
Data Structures Using C Practical File
PDF
C Prog - Array
PDF
Data Structure using C
PDF
10 template code program
PDF
Defcon 23 - Daniel Selifonov - drinking from LETHE
DOCX
SaraPIC
PPSX
C programming array & shorting
PDF
C programms
DOCX
DOCX
Os lab file c programs
DOC
Daa practicals
PDF
Cn os-lp lab manual k.roshan
PDF
C faq pdf
DOCX
DAA Lab File C Programs
PPTX
4. chapter iii
DOCX
ADA FILE
All important c programby makhan kumbhkar
Basic c programs updated on 31.8.2020
Best C Programming Solution
Data Structures Using C Practical File
C Prog - Array
Data Structure using C
10 template code program
Defcon 23 - Daniel Selifonov - drinking from LETHE
SaraPIC
C programming array & shorting
C programms
Os lab file c programs
Daa practicals
Cn os-lp lab manual k.roshan
C faq pdf
DAA Lab File C Programs
4. chapter iii
ADA FILE
Ad

Viewers also liked (16)

PDF
Ds using c 2009
PDF
Levantamento classe 500 ciências naturais e matemática
PDF
Monotica.gr
PDF
6 Steps to Unlocking the Power of Location
DOCX
Hand made
PPTX
Μονώσεις MONOTICA 2015
PDF
Anuário Macaé 2012 v. 1
PDF
PDF
Environmental impact assessment training resource manual unep
PPT
Apresentação normas para trabalho acadêmico
PDF
Repetto, Robert jobs competitiveness and environmental
PPT
Treinamento Busca de Periodicos no Portal Capes
PDF
Normas para tabular IBGE
Ds using c 2009
Levantamento classe 500 ciências naturais e matemática
Monotica.gr
6 Steps to Unlocking the Power of Location
Hand made
Μονώσεις MONOTICA 2015
Anuário Macaé 2012 v. 1
Environmental impact assessment training resource manual unep
Apresentação normas para trabalho acadêmico
Repetto, Robert jobs competitiveness and environmental
Treinamento Busca de Periodicos no Portal Capes
Normas para tabular IBGE
Ad

Similar to String (20)

PPTX
Computer Programming Utilities the subject of BE first year students, and thi...
PPTX
Module-2_Strings concepts in c programming
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
PDF
9 character string &amp; string library
PDF
c programming
PDF
[ITP - Lecture 17] Strings in C/C++
PDF
String notes
PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
PPT
String & its application
PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
PPTX
pps unit 3.pptx
PPTX
programming for problem solving using C-STRINGSc
PDF
Strings part2
PPTX
C programming - String
PPT
strings
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8
PPTX
Handling of character strings C programming
Computer Programming Utilities the subject of BE first year students, and thi...
Module-2_Strings concepts in c programming
CSE 1102 - Lecture_7 - Strings_in_C.pptx
9 character string &amp; string library
c programming
[ITP - Lecture 17] Strings in C/C++
String notes
THE FORMAT AND USAGE OF STRINGS IN C.PPT
String & its application
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
Lecture 15_Strings and Dynamic Memory Allocation.pptx
pps unit 3.pptx
programming for problem solving using C-STRINGSc
Strings part2
C programming - String
strings
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8
Handling of character strings C programming

More from SANTOSH RATH (20)

DOCX
Lesson plan proforma database management system
DOCX
Lesson plan proforma progrmming in c
DOCX
Expected questions tc
PDF
Expected questions tc
PDF
Module wise format oops questions
PDF
2011dbms
PDF
2006dbms
PDF
( Becs 2208 ) database management system
PDF
Rdbms2010
DOCX
Expected Questions TC
PDF
Expected questions tc
DOCX
Expected questions for dbms
PDF
Expected questions for dbms
PDF
Oops model question
PDF
System programming note
DOCX
Operating system notes
PDF
Os notes
PDF
OS ASSIGNMENT 2
PDF
OS ASSIGNMENT-1
PDF
OS ASSIGNMENT 3
Lesson plan proforma database management system
Lesson plan proforma progrmming in c
Expected questions tc
Expected questions tc
Module wise format oops questions
2011dbms
2006dbms
( Becs 2208 ) database management system
Rdbms2010
Expected Questions TC
Expected questions tc
Expected questions for dbms
Expected questions for dbms
Oops model question
System programming note
Operating system notes
Os notes
OS ASSIGNMENT 2
OS ASSIGNMENT-1
OS ASSIGNMENT 3

Recently uploaded (20)

PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
PDF
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
PPTX
Neurological complocations of systemic disease
PDF
FYJC - Chemistry textbook - standard 11.
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PDF
Chevening Scholarship Application and Interview Preparation Guide
PDF
CAT 2024 VARC One - Shot Revision Marathon by Shabana.pptx.pdf
PPTX
Neurology of Systemic disease all systems
PPTX
IT infrastructure and emerging technologies
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PDF
Review of Related Literature & Studies.pdf
PDF
The TKT Course. Modules 1, 2, 3.for self study
PDF
Diabetes Mellitus , types , clinical picture, investigation and managment
PPTX
Unit 1 aayurveda and nutrition presentation
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PPT
hemostasis and its significance, physiology
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PDF
Disorder of Endocrine system (1).pdfyyhyyyy
hsl powerpoint resource goyloveh feb 07.ppt
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
Neurological complocations of systemic disease
FYJC - Chemistry textbook - standard 11.
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
Chevening Scholarship Application and Interview Preparation Guide
CAT 2024 VARC One - Shot Revision Marathon by Shabana.pptx.pdf
Neurology of Systemic disease all systems
IT infrastructure and emerging technologies
ACFE CERTIFICATION TRAINING ON LAW.pptx
MMW-CHAPTER-1-final.pptx major Elementary Education
Review of Related Literature & Studies.pdf
The TKT Course. Modules 1, 2, 3.for self study
Diabetes Mellitus , types , clinical picture, investigation and managment
Unit 1 aayurveda and nutrition presentation
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
hemostasis and its significance, physiology
Theoretical for class.pptxgshdhddhdhdhgd
Disorder of Endocrine system (1).pdfyyhyyyy

String

  • 1. !!!! """" Strings/Character Array: in C language the group of characters, digits and symbols enclosed within quotation marks are called string. - The string always declared as character array. - In other word character array are called string. - Every string is terminated with ‘0’ (NULL) character. - The null character is a byte with all bits at logic zero. - For example: char name[ ]={‘S’,’A’,’N’,’T’,’T’,’O’,’S’,’H’}; - Each character of the string occupies 1 byte of memory. - The last character is always‘0’. - It is not compulsory to write, because the compiler automatically put’0’ at the end of character array or string. - The character array stored in contiguous memory locations - For example Memory map of string 1001 1001 1002 1003 1004 1005 1006 1007 Declaration and initialization of string: Char name [ ] =”SANTOSH”; Q. Write a program to display string Void main () { Char name [6] = {‘J’,’A’,’C’,’K’,’Y’}; Clrscr (); Printf (“Nam=%s”, name); } Output: JACKY S A N T O S H 0
  • 2. !!!! """" Important Note: it character array no need of write & in scanf statement because as we know that string is a collection of character, which is also called character array. The character are arranged or stored in contiguous memory location, so no need of address to store the string. How to read a character - To read a character use the following function - char getch() - char getche() Difference between getch() and getche(): - In case of getch() the input data does not visible on screen. - In case of getche() the input data visible on screen. How to display a character: - To display a character use following function. - putch() void putch(data) How to read a string: - To read a string use following function - gets(): whole string is accepted How to display a string: - puts ( ): it is used to display a string. Example: #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[10],i; clrscr(); printf("Enter a string"); gets(a);// to read a string
  • 3. !!!! """" puts(a);// it is used to display a string printf("%s",a);//display the string for(i=0;a[i]!='0';i++) printf("%c",a[i]); getch(); } Output: Enter a string: JACKY JACKY JACKY JACKY Explanation: ill print three times because for gets (),puts(),and printf(); Standard String Functions: Function Description Strlen() Determine length of string Strcpy() copies a string from source to destination Strcmp() a) compare character of two string (function determine between small and big) b) if the two string equal it return zero otherwise it return nonzero. c) it the ASCII value of two string. d) it stop when either end of string is reached or the corresponding character are not same. Strcat() append source string to destination string. Strrev() reverse all character of a string. Strlwr() it is used to convert a string to lower case. Tolower() it is used to covert a character to lower case Strupr() it is used to convert string to upper case. Touppper() it is used to convert a character to upper case
  • 4. !!!! """" Program: WAP to find the length of string Strlen() #include<stdio.h> #include<conio.h> #include<string.h> void main() { char p[50]; int len; clrscr(); printf("Enter a Text:n"); gets(p); len=strlen(p); printf("length of string=%d",len); getch(); } Program: WAP to find the length of string without using Strlen() #include<stdio.h> #include<conio.h> #include<string.h> void main() { char p[50]; int len=0,i; clrscr(); printf("Enter a string:n"); gets(p); for(i=0;p[i]!='0';i++) len++; printf("length of string %s=%d",p,len); getch(); }
  • 5. !!!! """" Program: WAP to input a string then copy one string to another string using strcpy (). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; clrscr(); printf("Enter a string:n"); gets(a); strcpy(b,a); printf("string %s is copy %s",a,b); getch(); } Program: WAP to input a string then copy one string to another string without using strcpy (). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; int i; clrscr(); printf("Enter a string:n"); gets(a); for(i=0;a[i]!='0';i++) b[i]=a[i]; b[i]='0'; printf("string %s is copy %s",a,b); getch(); }
  • 6. !!!! """" Program: WAP to input two string then joined it using strcat() #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; int i; clrscr(); printf("Enter ist string:n"); gets(a); printf("Enter 2nd string:n"); gets(b); strcat(a,b); printf("%s",a); getch(); } Program: WAP to input two string then compare it using strcmp(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; clrscr(); printf("n Enter 1st string"); gets(a); printf("Enter 2nd string"); gets(b); if(strcmp(a,b)==0) printf("equal"); else
  • 7. !!!! """" printf("not equal"); getch(); } Program: WAP to input two string then compare it without using strcmp(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; int i=0; clrscr(); printf("n Enter 1st string"); gets(a); printf("Enter 2nd string"); gets(b); while(a[i]!='0'&&b[i]!='0'&&a[i]==b[i]) i++; if(a[i]==b[i]) printf("equal"); else printf("not equal"); getch(); } Program: WAP to input a string then reverse it using strrev(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; clrscr();
  • 8. !!!! """" printf("n Enter 1st string"); gets(a); strrev(a); printf("n %s",a); getch(); } Program: WAP to input a string then reverse it without using strrev(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50],b[50]; int i,k=0; clrscr(); printf("n Enter a string"); gets(a); for(i=strlen(a)-1;i>=0;i--) b[k++]=a[i]; b[k]='0'; printf("n %s",b); getch(); } Program: WAP to input a string then convert it into lower case using strrev(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; clrscr();
  • 9. !!!! """" printf("n Enter a string"); gets(a); strlwr(a); printf("n %s",a); getch(); } Program: WAP to input a string then convert it into lower case without using strlwr(). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int i; clrscr(); printf("n Enter a string"); gets(a); for(i=0;a[i]!='0';i++) { if(a[i]>=65&&a[i]<=90) a[i]=a[i]+32; } printf("n %s",a); getch(); } Program: WAP to input a string then convert it into lower case using tolower(). #include<stdio.h> #include<conio.h> #include<string.h> void main() {
  • 10. !!!! """" char a[50]; int i; clrscr(); printf("n Enter a string"); gets(a); for(i=0;a[i]!='0';i++) { if(a[i]>=65&&a[i]<=90) a[i]=tolower a[i]; } printf("n %s",a); getch(); } Program: WAP to input a string then convert it into lower case using strupr (). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; clrscr(); printf("n Enter a string"); gets(a); strupr(a); printf("n %s",a); getch(); } Program: WAP to input a string then convert it into lower case without using strupr (). #include<stdio.h> #include<conio.h> #include<string.h>
  • 11. !!!! """" void main() { char a[50]; int i; clrscr(); printf("n Enter a string"); gets(a); for(i=0;a[i]!='0';i++) { if(a[i]>=97&&a[i]<=122) a[i]=a[i]-32; } printf("n %s",a); getch(); } Program: WAP to input a string then find out occurrence of each character. #include<string.h> #include<stdio.h> #include<conio.h> void main() { char a[50]; int i,k,j,c; clrscr(); printf("Enter a string"); gets(a); for(i=0;i<strlen(a);i++) { c=1; for(j=i+1;j<strlen(a);j++) { if(a[i]==a[j])
  • 12. !!!! """" { c++; for(k=j;k<strlen(a);k++) a[k]=a[k+1]; j--; } } printf("n%c is print %d times",a[i],c); } getch(); } Program: WAP to input a string then find out how many words are there. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int w=0,i=0; clrscr(); printf("n Enter a string"); gets(a); for(i=0;i<strlen(a);i++) { if(a[i]==32) w++; } printf("n no of words=%d",w); getch(); }
  • 13. !!!! """" Program: WAP to input a string then find out how many digits, space, alphabets, special symbols. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int i,p=0,d=0,s=0,sp=0; clrscr(); printf("n Enter a string"); gets(a); for(i=0;i<strlen(a);i++) { if(a[i]>=65&&a[i]<=90||a[i]>=97&&a[i]<=122) p++; else if(a[i]>=48&&a[i]<257) d++; else if(a[i]==32) s++; else sp++; } printf("n no of alphabets=%d",p); printf("n no of digits=%d",d); printf("n no of space=%d",s); printf("n no of special symbol=%d",sp); getch(); }
  • 14. !!!! """" Program: WAP to input a string then find out how many vowels are there. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int i,v=0; clrscr(); printf("n Enter a string"); gets(a); for(i=0;a[i]!='0';i++) { if(a[i]=='a'||a[i]=='A'|| a[i]=='e'||a[i]=='E'|| a[i]=='i'||a[i]=='I'|| a[i]=='o'||a[i]=='O'|| a[i]=='u'||a[i]=='U') v++; } printf("n Total no of vowes=%d",v); getch(); } Program: WAP to input a string then convert into lower case. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[50]; int i; clrscr();
  • 15. !!!! """" printf("n Enter a string"); gets(a); for(i=0;a[i]!='0';i++) { if(a[i]>=65&&a[i]<=90) a[i]=tolower a[i]; } printf("n %s",a); getch(); } Program: WAP to input a string then check string is palindrome or not. #include<stdio.h> #include<string.h> main() { char a[100], b[100]; printf("Enter the string to check if it is a palindromen"); gets(a); strcpy(b,a); strrev(b); if( strcmp(a,b) == 0 ) printf("Entered string is a palindrome.n"); else printf("Entered string is not a palindrome.n"); return 0; }
  • 16. !!!! """" Program: WAP to input a string then construct a structure. #include<stdio.h> #include<string.h> main() { char string[100]; int c, k, length; printf("Enter a stringn"); gets(string); length = strlen(string); for ( c = 0 ; c < length ; c++ ) { for( k = 0 ; k <= c ; k++ ) { printf("%c", string[k]); } printf("n"); } return 0; } Program: WAP to input a string then sorting of string . #include<stdio.h> int main(){ int i,j,n; char str[20][20],temp[20]; puts("Enter the no. of string to be sorted"); scanf("%d",&n); for(i=0;i<=n;i++) gets(str[i]); for(i=0;i<=n;i++) for(j=i+1;j<=n;j++){ if(strcmp(str[i],str[j])>0){ strcpy(temp,str[i]);
  • 17. !!!! """" strcpy(str[i],str[j]); strcpy(str[j],temp); } } printf("The sorted stringn"); for(i=0;i<=n;i++) puts(str[i]); return 0; } Program: WAP to input a string then check string is palindrome or not. #include<stdio.h> #include<string.h> main() { char a[100]; int c, k, length; printf("Enter a stringn"); gets(string); length = strlen(string); for ( c = length-1; c >=0 ; c-- ) { b[k]=’0’; b[k++]=a[i]; } If(b[i]=a[i]) Printf(“String is palindrome”); } else printf("not a palindrome”); getch();
  • 18. !!!! """" Program: WAP to input a string then input a character and check occurrence of character. #include<stdio.h> #include<string.h> main() { char a[100],ch; int i,c=0; printf("Enter a stringn"); gets(string); printf("Enter a stringn"); ch=getch(); for ( i=0;i<strlen(a);i++) { If[a[i]==ch) C++; } Printf(“Total no of %c in string %d”,c); } getch(); }