SlideShare a Scribd company logo
Strings
• A special kind of array is an array of characters
ending in the null character 0 called string array
s
• A string is declared as an array of characters
• char s[10]
• char p[30]
• When declaring a string don’t forget to leave a s
pace for the null character which is also known a
s the string terminator character
C offers four main operations on str
ings
• strcpy - copy one string into another
• strcat - append one string onto the right si
de of the other
• strcmp – compare alphabetic order of two
strings
• strlen – return the length of a string
strcpy
• strcpy(destinationstring, sourcestring)
• Copies sourcestring into destinationstring
• For example
• strcpy(str, “hello world”); assigns “hello wo
rld” to the string str
Example with strcpy
#include <stdio.h>
#include <string.h>
main()
{
char x[] = “Example with strcpy”;
char y[25];
printf(“The string in array x is %s n “, x);
strcpy(y,x);
printf(“The string in array y is %s n “, y);
}
strcat
• strcat(destinationstring, sourcestring)
• appends sourcestring to right hand side of destin
ationstring
• For example if str had value “a big ”
• strcat(str, “hello world”); appends “hello world” to
the string “a big ” to get
• “ a big hello world”
Example with strcat
#include <stdio.h>
#include <string.h>
main()
{
char x[] = “Example with strcat”;
char y[]= “which stands for string concatenation”;
printf(“The string in array x is %s n “, x);
strcat(x,y);
printf(“The string in array x is %s n “, x);
}
strcmp
• strcmp(stringa, stringb)
• Compares stringa and stringb alphabetically
• Returns a negative value if stringa precedes stri
ngb alphabetically
• Returns a positive value if stringb precedes strin
ga alphabetically
• Returns 0 if they are equal
• Note lowercase characters are greater than Upp
ercase
Example with strcmp
#include <stdio.h>
#include <string.h>
main()
{
char x[] = “cat”;
char y[]= “cat”;
char z[]= “dog”;
if (strcmp(x,y) == 0)
printf(“The string in array x %s is equal to t
hat in %s n “, x,y);
continued
if (strcmp(x,z) != 0)
{printf(“The string in array x %s is not equal to that in z %s n “,
x,z);
if (strcmp(x,z) < 0)
printf(“The string in array x %s precedes that in z %s n “, x,z);
else
printf(“The string in array z %s precedes that in x %s n “, z,x);
}
else
printf( “they are equal”);
}
strlen
• strlen(str) returns length of string excluding
null character
• strlen(“tttt”) = 4 not 5 since 0 not counted
Example with strlen
#include <stdio.h>
#include <string.h>
main()
{
int i, count;
char x[] = “tommy tucket took a tiny ticket ”;
count = 0;
for (i = 0; i < strlen(x);i++)
{
if (x[i] == ‘t’) count++;
}
printf(“The number of t’s in %s is %d n “, x,count);
}
Vowels Example with strlen
#include <stdio.h>
#include <string.h>
main()
{
int i, count;
char x[] = “tommy tucket took a tiny ticket ”;
count = 0;
for (i = 0; i < strlen(x);i++)
{
if ((x[i] == ‘a’)||(x[i]==‘e’)||(x[i]==‘I’)||(x[i]==‘o’)||(x[i]==‘u’)) count+
+;
}
printf(“The number of vowels’s in %s is %d n “, x,count);
}
No of Words Example with strlen
#include <stdio.h>
#include <string.h>
main()
{
int i, count;
char x[] = “tommy tucket took a tiny ticket ”;
count = 0;
for (i = 0; i < strlen(x);i++)
{
if ((x[i] == ‘ ‘) count++;
}
printf(“The number of words’s in %s is %d n “, x,count+1);
}
No of Words Example with more th
an one space between words
#include <stdio.h>
#include <string.h>
main()
{
int i,j, count;
char x[] = “tommy tucket took a tiny ticket ”;
count = 0;
for (i = 0; i < strlen(x);i++)
{
if ((x[i] == ‘ ‘)
{ count++;
for(j=i;x[j] != ‘ ‘;j++);
i = j;
}
}
printf(“The number of words’s in %s is %d n “, x,count+1);
}
Input output functions of characters
and strings
• getchar() reads a character from the scree
n in a non-interactive environment
• getche() like getchar() except interactive
• putchar(int ch) outputs a character to scre
en
• gets(str) gets a string from the keyboard
• puts(str) outputs string to screen
Characters are at the heart of string
s
Exercise 1
Output
1
1 2
1 2 3
1 2 3 4
………….
1 2 3 4 5 6 7 8 9 10
Exercise 1
#include <stdio.h>
main()
{
int i,j;
for(j = 1; j <= 10; j++)
{
for(i=1;i <= j;i++)
{
printf(“%d “,i);
}
printf(“n“);
}
}
Exercise 2
Output
*
* *
* * *
* * * *
…………….
* * * * * * * * * *
Exercise 2
#include <stdio.h>
main()
{
int i,j;
for(j = 1; j <= 10; j++)
{
for(i=1;i <= j;i++)
{
printf(“* “);
}
printf(“n“);
}
}
Exercise 3
• Output
***********
* *
* *
* *
* *
* *
* *
* *
* *
***********
#include <stdio.h>
main()
{
int i,j;
for(j = 1; j <= 10; j++)
{
printf(“* “);
for(i=1;i <= 8;i++)
{
if ((j==1) || (j==10)) printf(“* “);
else
printf(“ “);
}
printf(“* n “);
}
}
Some Useful C Character Functi
ons
• Don't forget to #include <ctype.h> to get t
he function prototypes.
Functions
• Function Return true if
• int isalpha(c); c is a letter.
• int isupper(c); c is an upper case
letter.
• int islower(c); c is a lower case letter.
• int isdigit(c); c is a digit [0-9].
More Functions
• Function Return true if
• int isxdigit(c); c is a hexadecimal digit
[0-9A-Fa-f].
• int isalnum(c); c is an alphanumeric character (c
is a letter or a digit);
• int isspace(c); c is a SPACE, TAB, RETURN,
NEWLINE, FORMFEED,
or vertical tab character.
Even More C Functions
• Function Return true if
• int ispunct(c); c is a punctuation
character (neither
control nor
alphanumeric).
• int isprint(c); c is a printing character.
• int iscntrl(c); c is a delete character
or ordinary control
character.
Still More C Functions
• Function Return true if
• int isascii(c); c is an ASCII character,
codeless than 0200.
• int toupper(int c); convert character c to
upper case (leave it
alone if not lower)
• int tolower(int c); convert character c to
lower case (leave it
alone if not upper)
• Program to Reverse Strings
• #include <stdio.h>
#include <string.h>
int main ()
{
• int i;
char a[10];
char temp;
//clrscr(); // only works on windows
gets(a);
• for (i = 0; a[i] != '0' ; i++);
• i--;
• for (int j = 0; j <= i/2 ; j++)
{
• temp = a[j];
a[j] = a[i - j];
a[i - j] = temp;
• }
printf("%s",a);
return(0);
•
Program to count the number of vo
wels in a string :
• Note Two different ways to declare strings
• One using pointers *str
• Two using character array char a[]
• #include <stdio.h>
#include <string.h>
• void main() {
• char *str;
• char a[]="aeiouAEIOU";
• int i,j,count=0;
• clrscr();
• printf("nEnter the stringn");
• gets(str);
• for(i=0;str[i]!='0';i++)
• {
• for(j=0;a[j]!='0';j++)
• if(a[j] == str[i]
• {
• count++;
• break;
• }
printf("nNo. of vowels = %d",count);
• }
•

More Related Content

What's hot (14)

PPTX
String Handling in c++
Fahim Adil
 
PPT
14 strings
Rohit Shrivastava
 
PPT
Strings Functions in C Programming
DevoAjit Gupta
 
PPTX
String in c programming
Devan Thakur
 
PPTX
P2 2017 python_strings
Prof. Wim Van Criekinge
 
PDF
05 c++-strings
Kelly Swanson
 
PPTX
Strings in Python
Amisha Narsingani
 
PPTX
Arrays
AnaraAlam
 
PPTX
Strings in C language
P M Patil
 
PDF
Strings
Michael Gordon
 
PPTX
Array and string
prashant chelani
 
PPTX
2017 biological databasespart2
Prof. Wim Van Criekinge
 
PPTX
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 
PPTX
String C Programming
Prionto Abdullah
 
String Handling in c++
Fahim Adil
 
14 strings
Rohit Shrivastava
 
Strings Functions in C Programming
DevoAjit Gupta
 
String in c programming
Devan Thakur
 
P2 2017 python_strings
Prof. Wim Van Criekinge
 
05 c++-strings
Kelly Swanson
 
Strings in Python
Amisha Narsingani
 
Arrays
AnaraAlam
 
Strings in C language
P M Patil
 
Array and string
prashant chelani
 
2017 biological databasespart2
Prof. Wim Van Criekinge
 
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 
String C Programming
Prionto Abdullah
 

Similar to Presentation more c_programmingcharacter_and_string_handling_ (20)

PPT
String manipulation techniques like string compare copy
Dr. T. Kalaikumaran
 
PPTX
String in programming language in c or c++
Samsil Arefin
 
PPTX
Module-2_Strings concepts in c programming
CHAITRAB29
 
PPT
Strings
Mitali Chugh
 
PDF
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
PDF
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
JNTUK KAKINADA
 
PDF
Strings part2
yndaravind
 
PPTX
C string
University of Potsdam
 
PPT
Strings in c
vampugani
 
PPTX
CSE 1102 - Lecture_7 - Strings_in_C.pptx
Salim Shadman Ankur
 
PPTX
C programming - String
Achyut Devkota
 
PDF
0-Slot21-22-Strings.pdf
ssusere19c741
 
PPTX
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
monimhossain14
 
PPTX
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
 
PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
shanthabalaji2013
 
PPT
Strings(2007)
svit vasad
 
PPT
string.ppt
lakshmanarao027MVGRC
 
PPTX
COm1407: Character & Strings
Hemantha Kulathilake
 
PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
abritip
 
String manipulation techniques like string compare copy
Dr. T. Kalaikumaran
 
String in programming language in c or c++
Samsil Arefin
 
Module-2_Strings concepts in c programming
CHAITRAB29
 
Strings
Mitali Chugh
 
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
PROBLEM SOLVING USING A PPSC- UNIT -3.pdf
JNTUK KAKINADA
 
Strings part2
yndaravind
 
Strings in c
vampugani
 
CSE 1102 - Lecture_7 - Strings_in_C.pptx
Salim Shadman Ankur
 
C programming - String
Achyut Devkota
 
0-Slot21-22-Strings.pdf
ssusere19c741
 
String_Slide.pptxStructure.pptxStructure.pptxStructure.pptxStructure.pptx
monimhossain14
 
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
 
THE FORMAT AND USAGE OF STRINGS IN C.PPT
shanthabalaji2013
 
Strings(2007)
svit vasad
 
COm1407: Character & Strings
Hemantha Kulathilake
 
Chapterabcdefghijklmnopqrdstuvwxydanniipo
abritip
 
Ad

More from KarthicaMarasamy (15)

PPTX
COMPUTER NETWORK -LAN ,WAN ,MAN FUNCTIONSpptx
KarthicaMarasamy
 
PPTX
Bayer's Theorem Naive Bayer's classifier
KarthicaMarasamy
 
PPTX
Roles of Datascience.pptx
KarthicaMarasamy
 
PPTX
DATASCIENCE.pptx
KarthicaMarasamy
 
PPTX
Software Testing 1.pptx
KarthicaMarasamy
 
PDF
powerpoint 1.pdf
KarthicaMarasamy
 
PPTX
class 3.pptx
KarthicaMarasamy
 
PPTX
class 2.pptx
KarthicaMarasamy
 
PPTX
Software Testing
KarthicaMarasamy
 
PPTX
Network (Hub,switches)
KarthicaMarasamy
 
PPTX
Computer network layers
KarthicaMarasamy
 
PPTX
C programming
KarthicaMarasamy
 
PPTX
Fundamentals steps in Digital Image processing
KarthicaMarasamy
 
PPTX
DIGITAL IMAGE PROCESSING
KarthicaMarasamy
 
PPTX
Network
KarthicaMarasamy
 
COMPUTER NETWORK -LAN ,WAN ,MAN FUNCTIONSpptx
KarthicaMarasamy
 
Bayer's Theorem Naive Bayer's classifier
KarthicaMarasamy
 
Roles of Datascience.pptx
KarthicaMarasamy
 
DATASCIENCE.pptx
KarthicaMarasamy
 
Software Testing 1.pptx
KarthicaMarasamy
 
powerpoint 1.pdf
KarthicaMarasamy
 
class 3.pptx
KarthicaMarasamy
 
class 2.pptx
KarthicaMarasamy
 
Software Testing
KarthicaMarasamy
 
Network (Hub,switches)
KarthicaMarasamy
 
Computer network layers
KarthicaMarasamy
 
C programming
KarthicaMarasamy
 
Fundamentals steps in Digital Image processing
KarthicaMarasamy
 
DIGITAL IMAGE PROCESSING
KarthicaMarasamy
 
Ad

Recently uploaded (20)

PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Dimensions of Societal Planning in Commonism
StefanMz
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 

Presentation more c_programmingcharacter_and_string_handling_

  • 1. Strings • A special kind of array is an array of characters ending in the null character 0 called string array s • A string is declared as an array of characters • char s[10] • char p[30] • When declaring a string don’t forget to leave a s pace for the null character which is also known a s the string terminator character
  • 2. C offers four main operations on str ings • strcpy - copy one string into another • strcat - append one string onto the right si de of the other • strcmp – compare alphabetic order of two strings • strlen – return the length of a string
  • 3. strcpy • strcpy(destinationstring, sourcestring) • Copies sourcestring into destinationstring • For example • strcpy(str, “hello world”); assigns “hello wo rld” to the string str
  • 4. Example with strcpy #include <stdio.h> #include <string.h> main() { char x[] = “Example with strcpy”; char y[25]; printf(“The string in array x is %s n “, x); strcpy(y,x); printf(“The string in array y is %s n “, y); }
  • 5. strcat • strcat(destinationstring, sourcestring) • appends sourcestring to right hand side of destin ationstring • For example if str had value “a big ” • strcat(str, “hello world”); appends “hello world” to the string “a big ” to get • “ a big hello world”
  • 6. Example with strcat #include <stdio.h> #include <string.h> main() { char x[] = “Example with strcat”; char y[]= “which stands for string concatenation”; printf(“The string in array x is %s n “, x); strcat(x,y); printf(“The string in array x is %s n “, x); }
  • 7. strcmp • strcmp(stringa, stringb) • Compares stringa and stringb alphabetically • Returns a negative value if stringa precedes stri ngb alphabetically • Returns a positive value if stringb precedes strin ga alphabetically • Returns 0 if they are equal • Note lowercase characters are greater than Upp ercase
  • 8. Example with strcmp #include <stdio.h> #include <string.h> main() { char x[] = “cat”; char y[]= “cat”; char z[]= “dog”; if (strcmp(x,y) == 0) printf(“The string in array x %s is equal to t hat in %s n “, x,y);
  • 9. continued if (strcmp(x,z) != 0) {printf(“The string in array x %s is not equal to that in z %s n “, x,z); if (strcmp(x,z) < 0) printf(“The string in array x %s precedes that in z %s n “, x,z); else printf(“The string in array z %s precedes that in x %s n “, z,x); } else printf( “they are equal”); }
  • 10. strlen • strlen(str) returns length of string excluding null character • strlen(“tttt”) = 4 not 5 since 0 not counted
  • 11. Example with strlen #include <stdio.h> #include <string.h> main() { int i, count; char x[] = “tommy tucket took a tiny ticket ”; count = 0; for (i = 0; i < strlen(x);i++) { if (x[i] == ‘t’) count++; } printf(“The number of t’s in %s is %d n “, x,count); }
  • 12. Vowels Example with strlen #include <stdio.h> #include <string.h> main() { int i, count; char x[] = “tommy tucket took a tiny ticket ”; count = 0; for (i = 0; i < strlen(x);i++) { if ((x[i] == ‘a’)||(x[i]==‘e’)||(x[i]==‘I’)||(x[i]==‘o’)||(x[i]==‘u’)) count+ +; } printf(“The number of vowels’s in %s is %d n “, x,count); }
  • 13. No of Words Example with strlen #include <stdio.h> #include <string.h> main() { int i, count; char x[] = “tommy tucket took a tiny ticket ”; count = 0; for (i = 0; i < strlen(x);i++) { if ((x[i] == ‘ ‘) count++; } printf(“The number of words’s in %s is %d n “, x,count+1); }
  • 14. No of Words Example with more th an one space between words #include <stdio.h> #include <string.h> main() { int i,j, count; char x[] = “tommy tucket took a tiny ticket ”; count = 0; for (i = 0; i < strlen(x);i++) { if ((x[i] == ‘ ‘) { count++; for(j=i;x[j] != ‘ ‘;j++); i = j; } } printf(“The number of words’s in %s is %d n “, x,count+1); }
  • 15. Input output functions of characters and strings • getchar() reads a character from the scree n in a non-interactive environment • getche() like getchar() except interactive • putchar(int ch) outputs a character to scre en • gets(str) gets a string from the keyboard • puts(str) outputs string to screen
  • 16. Characters are at the heart of string s
  • 17. Exercise 1 Output 1 1 2 1 2 3 1 2 3 4 …………. 1 2 3 4 5 6 7 8 9 10
  • 18. Exercise 1 #include <stdio.h> main() { int i,j; for(j = 1; j <= 10; j++) { for(i=1;i <= j;i++) { printf(“%d “,i); } printf(“n“); } }
  • 19. Exercise 2 Output * * * * * * * * * * ……………. * * * * * * * * * *
  • 20. Exercise 2 #include <stdio.h> main() { int i,j; for(j = 1; j <= 10; j++) { for(i=1;i <= j;i++) { printf(“* “); } printf(“n“); } }
  • 21. Exercise 3 • Output *********** * * * * * * * * * * * * * * * * ***********
  • 22. #include <stdio.h> main() { int i,j; for(j = 1; j <= 10; j++) { printf(“* “); for(i=1;i <= 8;i++) { if ((j==1) || (j==10)) printf(“* “); else printf(“ “); } printf(“* n “); } }
  • 23. Some Useful C Character Functi ons • Don't forget to #include <ctype.h> to get t he function prototypes.
  • 24. Functions • Function Return true if • int isalpha(c); c is a letter. • int isupper(c); c is an upper case letter. • int islower(c); c is a lower case letter. • int isdigit(c); c is a digit [0-9].
  • 25. More Functions • Function Return true if • int isxdigit(c); c is a hexadecimal digit [0-9A-Fa-f]. • int isalnum(c); c is an alphanumeric character (c is a letter or a digit); • int isspace(c); c is a SPACE, TAB, RETURN, NEWLINE, FORMFEED, or vertical tab character.
  • 26. Even More C Functions • Function Return true if • int ispunct(c); c is a punctuation character (neither control nor alphanumeric). • int isprint(c); c is a printing character. • int iscntrl(c); c is a delete character or ordinary control character.
  • 27. Still More C Functions • Function Return true if • int isascii(c); c is an ASCII character, codeless than 0200. • int toupper(int c); convert character c to upper case (leave it alone if not lower) • int tolower(int c); convert character c to lower case (leave it alone if not upper)
  • 28. • Program to Reverse Strings • #include <stdio.h> #include <string.h> int main () { • int i; char a[10]; char temp; //clrscr(); // only works on windows gets(a); • for (i = 0; a[i] != '0' ; i++); • i--; • for (int j = 0; j <= i/2 ; j++) { • temp = a[j]; a[j] = a[i - j]; a[i - j] = temp; • } printf("%s",a); return(0); •
  • 29. Program to count the number of vo wels in a string : • Note Two different ways to declare strings • One using pointers *str • Two using character array char a[] • #include <stdio.h> #include <string.h> • void main() { • char *str; • char a[]="aeiouAEIOU"; • int i,j,count=0; • clrscr(); • printf("nEnter the stringn"); • gets(str); • for(i=0;str[i]!='0';i++) • { • for(j=0;a[j]!='0';j++) • if(a[j] == str[i] • { • count++; • break; • } printf("nNo. of vowels = %d",count); • } •