The reason why fgets
is only reading partial input is because the buffer too small. You need to increase the buffer size. Below is working code And what is the content of input[]
array?
void main()
{
int i,j,k,n;
char key[64], input[64], word[64], output[64];
printf("Enter key:");
fgets(input, sizeof(key), stdin);
input[strlen(input)-1] = '\0';
printf("Enter word:");
fgets(word, sizeof(word), stdin);
word[strlen(word)-1] = '\0';
//I am trying to store two
for (i = 0; i<7; i++) { //user-inputted arrays and then
for (j = 0; j<5; j++) { //do stuff with them. Fails before
if (word[i] == key[j]) { //I even get to the for loop.
output[i] = input[j];
}
}
}
printf("%s\n",output);
}