: This program is aimed at printing all the occurences of a particular letter in a sentence when that particular character is typed.(if anybody knows hangaroo game, this program is using the same concept with it)
:
: I tried using static to define my temp variable in printpart() functn.
: It worked half way, cos the static storage temp inside the printpart() function is complainimg of segmentation fault when like 9 characters are printed.
:
:
: #include <iostream>
: #include <string>
: #include <cctype>
: #include <cstdlib>
:
: using namespace std;
:
: int ARR[6] ;
: int KOUNT = 0;
: int WRONG = 0;
:
: void printpart(string,char);
: bool check(char, string);
: string replace(string);
: char asterik(char);
:
: int main()
: {int n;
: char ch;
: string sentence = "This code prints sentence character by character";
: cout << "\t" << sentence << endl;
:
: /*To check if choice is right and print all the occurence of the
: * the number chosen in the sentence*/
:
: do
: {cin >> ch;
: if(check(ch,sentence))
: {system("clear");
: printpart(sentence,ch);
: }
: else wrong++;
: }
: while(wrong != 4);
:
: return 0;
: }
:
:
:
: void printpart(string sentence,char ch)
: { int len = sentence.length();
: static string temp = replace(sentence);
: int i = 0;
: while(i < len)
: {if (ch == sentence[i])
: temp[i] = ch; //when the number of assigned character is nine it complains of segmentation fault.
: i++;
: }
: cout << "\t" << temp << endl;
: cout << sentence;
: }
:
: Does anybody know how to go about the question?
:
: This is an instance of what I'm saying.
:
: string word = "this a feast of life";
: i want to make it in such a way that if i type 'h'
: it'll display like this:
: *h** * ***** ** **** //character printed is 1
: type f
: *h** * f**** *f **f* // character printed is 4
: type a
: *h** a f*ast *f **f* // character printed is 8
type e
it will give segmentation err.

so the problem is whenever the number of characters(non asterik) printed is 9 or above it will crash ,give segmentation err.
)