-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_game.c
51 lines (41 loc) · 1.02 KB
/
string_game.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *alphabet = "abcdefghijklmnopqrstuvwxyz";
int getPos(char c){
int i;
for(i = 0; i < strlen(alphabet); i++){
if(c == alphabet[i])
break;
}
return i;
}
int main()
{
char s1[50], s2[50];
int i, step = 0;
giris:
printf("Herhangi bir kelime girin > ");
fgets(s1, 50, stdin);
printf("Donusturmek istediginiz kelimeyi girin (Uuzunluk ayni olmali) > ");
fgets(s2, 50, stdin);
if(strlen(s1) != strlen(s2)){
printf("Uzunluklar ayni degil.\n\n");
goto giris;
}
printf("Donusum uygulaniyor...\n\n\t%s", s1);
for(i = 0; i < strlen(s1); i++){
while(s1[i] != s2[i]){
if(getPos(s1[i]) < getPos(s2[i])){
s1[i]++;
}else{
s1[i]--;
}
step++;
printf("%d:\t%s", i+1, s1);
}
}
printf("\nDonusturulen kelime: %s", s1);
printf("\n%d adimda cevrildi. \n\n", step);
return 0;
}