the project ask the user to enter a string and then prompts the user to enter a character. the program should display the location of the first occurrence of the character in the string.
for example: the user enters the string "abcde", and the character "d", the program should say the character d is character number 4 in the string.
okay i got it to count the number of characters but i have no idea how to locate the second character and display the location, if anybody can guide me to the proper way of coding , i would greatly appreciate it.Code:#include <iostream.h> int main() { char line[81]; char fat[81]; char* ch_ptr = line; char* ch_ftr = fat; int count = 0; cout << "\nEnter a string of characters:\n\n"; cin.getline(line, 81); cout << "\nEnter one character in the previous string\n\n "; cin.getline(fat, 81); while (*ch_ptr == 'fat') { ++count; ++ch_ptr; } cout << "\nThe string you entered is in the " << count << "space ."; return 0; }



LinkBack URL
About LinkBacks


