comparing characters (letters) on c -
im making program compare letters. goal of make hangman game. cant make letter comparison work
#include<stdio.h> #include<conio.h> #include<string.h> int c=0,x; char a[50],b[50],n[50],j,h; char a1[50],b1[50],y; main() { printf("player 1:enter word\n"); gets(n); x=strlen(n); printf("%d letters\n",x); puts("now enter word letter letter"); { gets(a); strcat(b,a); c++; } while(c!=x); printf("%s",b); getch(); system("cls"); c=0; puts("player 2:try guess word letter letter"); { gets(a1); y=strcmp(a,a1); printf("%d",y); strcat(b1,a1); c++; } while(c!=x); printf("%s",b1); getch(); return 0; }
im having problems in particular player 2 section. not supposed whole comparing letters program; comparing letters whatever in player 1 section (but keeps trowing 1 , -1 , have no idea how fix this).
im sure little bit more programming knowledge, should able fix this, im beginner trying learn on own. tip extremely helpful :)
in code, a
stores temporary value of player1's input, if player1 input "abide", result a = "e"
after plyaer1's loop. in player2's loop, compare "e" user's input.
a solution may compares first character instead of using strcmp
y = b[c] - a1[0];
Comments
Post a Comment