Acasa Tehnologie Numarare caracter

Numarare caracter

by Dragos Schiopu

>Numara de cate ori apare un caracter intr-un string.

#include <conio.h>
#include <stdio.h>

void main()
{
char sir[30];
char a;
int count=0;
printf("Dati text:");
gets(sir);
printf("Dati character: ");
a=getch();

for(int i=0;sir[i]!='';i++)
if(sir[i]==a) count=count+1;
printf("Caractersul %c apare de %d ori",a,count);

getch();
clrscr();
}

s-ar putea sa-ti placa