SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
!!!!
""""
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();
}

Más contenido relacionado

La actualidad más candente

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solutionyogini sharma
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Defcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEDefcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEFelipe Prado
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programsKandarp Tiwari
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanriturajj
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
 

La actualidad más candente (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
10 template code program
10 template code program10 template code program
10 template code program
 
Defcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEDefcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHE
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
C programms
C programmsC programms
C programms
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 

Destacado (16)

Ds using c 2009
Ds using c 2009Ds using c 2009
Ds using c 2009
 
Levantamento classe 500 ciências naturais e matemática
Levantamento classe 500   ciências naturais e matemáticaLevantamento classe 500   ciências naturais e matemática
Levantamento classe 500 ciências naturais e matemática
 
Monotica.gr
Monotica.grMonotica.gr
Monotica.gr
 
6 Steps to Unlocking the Power of Location
6 Steps to Unlocking the Power of Location6 Steps to Unlocking the Power of Location
6 Steps to Unlocking the Power of Location
 
Hand made
Hand made Hand made
Hand made
 
Μονώσεις MONOTICA 2015
Μονώσεις MONOTICA 2015Μονώσεις MONOTICA 2015
Μονώσεις MONOTICA 2015
 
Anuário Macaé 2012 v. 1
Anuário Macaé 2012 v. 1Anuário Macaé 2012 v. 1
Anuário Macaé 2012 v. 1
 
2 determinan matriks
2 determinan matriks2 determinan matriks
2 determinan matriks
 
Quiz Cultural - Regras
Quiz Cultural - RegrasQuiz Cultural - Regras
Quiz Cultural - Regras
 
Environmental impact assessment training resource manual unep
Environmental impact assessment training resource manual unepEnvironmental impact assessment training resource manual unep
Environmental impact assessment training resource manual unep
 
Apresentação normas para trabalho acadêmico
Apresentação normas para trabalho acadêmicoApresentação normas para trabalho acadêmico
Apresentação normas para trabalho acadêmico
 
Repetto, Robert jobs competitiveness and environmental
Repetto, Robert jobs competitiveness and environmentalRepetto, Robert jobs competitiveness and environmental
Repetto, Robert jobs competitiveness and environmental
 
Curso NBR 6023
Curso NBR 6023Curso NBR 6023
Curso NBR 6023
 
Treinamento Busca de Periodicos no Portal Capes
Treinamento Busca de Periodicos no Portal CapesTreinamento Busca de Periodicos no Portal Capes
Treinamento Busca de Periodicos no Portal Capes
 
Flow handbook
Flow handbookFlow handbook
Flow handbook
 
Normas para tabular IBGE
Normas para tabular IBGENormas para tabular IBGE
Normas para tabular IBGE
 

Similar a String (20)

Strings IN C
Strings IN CStrings IN C
Strings IN C
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
week-6x
week-6xweek-6x
week-6x
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C programming
C programmingC programming
C programming
 
Unit 3 Input Output.pptx
Unit 3 Input Output.pptxUnit 3 Input Output.pptx
Unit 3 Input Output.pptx
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
 
string , pointer
string , pointerstring , pointer
string , pointer
 
C file
C fileC file
C file
 
C basics
C basicsC basics
C basics
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
14 strings
14 strings14 strings
14 strings
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
String in c
String in cString in c
String in c
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
week-7x
week-7xweek-7x
week-7x
 
String_C.pptx
String_C.pptxString_C.pptx
String_C.pptx
 

Más de SANTOSH RATH

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management systemSANTOSH RATH
 
Lesson plan proforma progrmming in c
Lesson plan proforma progrmming in cLesson plan proforma progrmming in c
Lesson plan proforma progrmming in cSANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tcSANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tcSANTOSH RATH
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questionsSANTOSH RATH
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management systemSANTOSH RATH
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TCSANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tcSANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbmsSANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbmsSANTOSH RATH
 
Oops model question
Oops model questionOops model question
Oops model questionSANTOSH RATH
 
System programming note
System programming noteSystem programming note
System programming noteSANTOSH RATH
 
Operating system notes
Operating system notesOperating system notes
Operating system notesSANTOSH RATH
 

Más de SANTOSH RATH (20)

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management system
 
Lesson plan proforma progrmming in c
Lesson plan proforma progrmming in cLesson plan proforma progrmming in c
Lesson plan proforma progrmming in c
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
 
2011dbms
2011dbms2011dbms
2011dbms
 
2006dbms
2006dbms2006dbms
2006dbms
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management system
 
Rdbms2010
Rdbms2010Rdbms2010
Rdbms2010
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TC
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Oops model question
Oops model questionOops model question
Oops model question
 
System programming note
System programming noteSystem programming note
System programming note
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
Os notes
Os notesOs notes
Os notes
 
OS ASSIGNMENT 2
OS ASSIGNMENT 2OS ASSIGNMENT 2
OS ASSIGNMENT 2
 
OS ASSIGNMENT-1
OS ASSIGNMENT-1OS ASSIGNMENT-1
OS ASSIGNMENT-1
 
OS ASSIGNMENT 3
OS ASSIGNMENT 3OS ASSIGNMENT 3
OS ASSIGNMENT 3
 

Último

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Último (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

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(); }