-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCP5CharArraycountnsearch.C
More file actions
36 lines (34 loc) · 873 Bytes
/
CP5CharArraycountnsearch.C
File metadata and controls
36 lines (34 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Title: WAP for finding(search) and counting characters from character array;
Programmer: Hitesh Patel Year/Div: FYBCA-1 RollNo: 999
Date: October 5, 2023
CP5CharArraycountnsearch.C
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
system("cls");
int i=0,counter=0;
char search;
char sname[10] = {'A','M','R','O','L','I','B','C','A','\0'};//declaring character array
char sname2[100];//declaring character array
printf("String1 Data= %s\n",sname);
printf("Enter String2 Data\n");
gets(sname2);
printf("\nEnter Character to Search Data\n");
scanf("%c",&search);
printf("OUTPUT USING FOR LOOP\n");//FORLOOP
for (i = 0; i < strlen(sname2); i++)
{
if(sname2[i]==search)
{
counter++;
}
else{
printf("%c",sname2[i]);
}
}
printf("\nTOTAL '%c' in your name2 = %d\n",search,counter);
}