15 Nisan 2013 Pazartesi

3 Satır bir metinde hangi harften kaç tane olduğunu bulan program

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main( void )
{
    char text[ 3 ][ 80 ],tampon[240]={0}; /* 3 lines of text */
char *searchPtr; /* pointer to search character */
char characters[ 26 ] = { 0 }; /* totals for each letter */
char say_characters[ 26 ] = { 0 };
int count = 0; /* total for current letter */
int i; /* loop counter */
int j; /* loop counter */
printf( "Enter three lines of text:\n" );
gets(text[0]);
gets(text[1]);
gets(text[2]);
strcat(tampon,text[0]);
strcat(tampon,text[1]);
strcat(tampon,text[2]); /* read three lines of text */

    for(j=0;j<strlen(tampon);j++){
        tampon[j]=tolower(tampon[j]);}/* convert letters to lowercase */
for(i=0;i<26;i++){
    characters[i]=(char)((int)'a'+i);
}
    searchPtr=tampon;
  
for(j=0;j<strlen(tampon);j++,searchPtr=searchPtr+1)
for(i=0;i<26;i++){
    if(characters[i]==*searchPtr){
    say_characters[i]++;
    }  
    }
/* loop through alphabet */


printf( "\nThe total occurrences of each character:\n" );
/* display totals for each character */
for ( i = 0; i <= 25; i++ ) {
printf( "%c:%3d\n", 'a' + i, say_characters[ i ] );
} /* end for */
return 0; /* indicate successful termination */
} /* end main */

Hiç yorum yok:

Yorum Gönder