Student Portfolio >> Index >> Coding >> Exercise 5
#include <iostream.h>
#include <math.h>
#include <string.h>
const int SIZE = 100;
int findchar(char [], char); int main()
{ char sentence[SIZE], character;
int var_pos;
cout<<"Enter a word: ";
cin.getline(sentence, SIZE);
// count = findchar(sentence);
//char character[SIZE];
cout<<"Enter a character: ";
//cin.getline(character, SIZE);
cin >> character;
var_pos = findchar(sentence, character);
cout<<"\nThe position of the character is "<<var_pos<<endl;
return 0;
}
int findchar(char sentence[], char character)
{
int i, character_pos=0;
for(i=0;i<strlen(sentence);i++)
if (sentence[i] == character )
character_pos = i+1;
return character_pos;
}
<< Back Forward >> |
Copyright 2005 Kerstin Kegel