C program to search all occurrences of a character in a given string using a while loop. | सी प्रोग्राम एक दिए गए स्ट्रिंग में एक पात्र के सभी घटनाओं को थोड़ी देर के लूप का उपयोग करके खोजता है।












C program to search all occurrences of a character in a given string using a while loop.




C program to search all occurrences of a character in a given string using a while loop.



#include <stdio.h> #define MAX 100 int main() { char text[MAX]; char search; int i; printf("\n Enter any string: "); gets(text); printf("\n Enter any character to search in the given string: "); search = getchar(); i=0; while(text[i]!='\0') { if(text[i] == search) { printf("'%c' is found at index %d\n", search, i); } i++; } return 0; }


Output:
Enter any string: I love c programcoding Enter any character to search: o 'o' is found at index 3 'o' is found at index 11 'o' is found at index 17



Exercise: 1
C program to search all occurrences of a character in a string.