1. Indentation.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _CRT_SECURE_NO_WARNINGS
int letterguess(char *text, int a);
int main(void)
{
char word[] = "asenine";
int x = strlen(word);
char input;
printf("%d", letterguess(word, x));
return 0;
}
int letterguess(char *text, int a)
{
char input;
scanf("%c", input);
for (int i = 0; i < a; i++) {
if (text[i] == input) {
return 1;
} else {
return 0;
}
}
}
Now you can easily see that the for loop in letterguess only runs once. It doesn't matter whether there is a match or not, it's returning either way.
Second, watch your scanf formats.
Code:
$ gcc -Wall foo.c
foo.c: In function ‘main’:
foo.c:12:8: warning: unused variable ‘input’ [-Wunused-variable]
char input;
^
foo.c: In function ‘letterguess’:
foo.c:20:9: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
scanf("%c", input);
^
foo.c:28:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
foo.c:20:3: warning: ‘input’ is used uninitialized in this function [-Wuninitialized]
scanf("%c", input);
^