Search a Character




// ---------------------------------------------------------
// Algorithm and Programming in C
// ---------------------------------------------------------
//
// Author : adhita muslim
// Written in C Language using MS Visual C++
// Copyright : 2007
//
// ---------------------------------------------------------

//menghitung jumlah karakter tertentu dlm suatu string
#include
#include

char kata[100],huruf;

int jumlah_huruf(char x)
{
int i,jum;

i=0;
jum=0;

for (i=0;kata[i]!=NULL;i++)
{
if(huruf==kata[i])
{
jum++;
printf("Found \"%c\" at position %i\n",huruf,i+1);
}
}
return jum;
}

void main()
{

printf("Input string : ");
gets(kata);
printf("\n");

printf("Input character : ");
huruf=getche();
printf("\n\n");

printf("\nThere are %i \"%c\" in \"%s\"\n",jumlah_huruf(huruf),huruf,kata);
printf("\n");
}

0 comments:

Post a Comment