Posts

Showing posts from March 13, 2013

String functions in C

1. C Program to Find the Frequency of Characters in a String 2 . C Program to Reverse a String by Passing it to Function Source Code 1: #include <stdio.h> int main (){ char c [ 1000 ], ch ; int i , count = 0 ; printf ( "Enter a string: " ); gets ( c ); printf ( "Enter a characeter to find frequency: " ); scanf ( "%c" ,& ch ); for ( i = 0 ; c [ i ]!= '\0' ;++ i ) { if ( ch == c [ i ]) ++ count ; } printf ( "Frequency of %c = %d" , ch , count ); return 0 ; } Output Enter a string: md. ahsan arif Enter a frequency to find frequency: a Frequency of a = 3   2:   #include <stdio.h> #include <string.h> void Reverse ( char str []); int main (){ char str [ 100 ]; printf ( "Enter a string to reverse: " ); gets ( str ); Reverse ( str ); printf ( "Reversed string: " ); puts ( s