#include using namespace std; /* Bir dizgi oyununda kullanıcıdan harfler girmesini istiyoruz. Kullanıcıdan aldığımız bu dizgide ardışık tekrar eden 2 harf varsa eğer bunları siliyoruz ve kullanıcıya bu şekilde kısaltılmış halini gösteriyoruz. örnek girdi 1 = aabcccdee çıktı = bcd örnek girdi 2 = abcdeeffffaaa çıktı = abcda */ char* f(char *s) { int counter = 0; while(s[counter]!='\0'){ if (s[counter]!=s[counter+1]){ cout << s[counter]; counter++; } else counter+=2; } return 0; } int main() { string dizgi; cout << "-------------------------" << endl << " Code without function" << endl << "-------------------------" << endl << "Please enter the words: "; cin >> dizgi; int lenght = dizgi.size(); char output[lenght+1]; int counter = 0; for (int i = 0; i < lenght; i++) { if (dizgi[i] != dizgi[i+1]) { output[counter] = dizgi[i]; counter++; } else { i++; } } cout << "Shortest output: " << output << endl; //NEDENİNİ ANLAMADIĞIM HALDE BU FONKSİYONU DA KULLANMAYA ÇALIŞINCA İKİSİ DE BOZULUYOR. cout << "\n-------------------------" << endl << " Code with function " << endl << "-------------------------" << endl; cout << "Enter the lenght:"; int lenghtf; cin >> lenghtf; cout << "Enter the words:"; char *s = (char*)malloc(sizeof(char)*lenghtf); cin >> s; f(s); }