fgets has more characters that its supposed to

Hi I'm trying to use fgets to take the string from stdin and store it in input, then it should compare with an array of words (over 50000 words long taken from a text file) using the strcmp method, but i could never get them to compare for some reason until I found out why here is my code.

char[] text;// <----------array is already full and working at this point I just 
char input[24];//         thought I'd include this for the memcpy
char check[24]="happ";
fgets(input,24, stdin);

for(int i=0; i < 50000; i++){
  memcpy(check, text[i], strlen(input));// this is supposed to get a substring

    if(strcmp(check, input) == 0){// this is supposed to auto complete 
        printf("%s",text[i]);}// say for example 4 letters are inputted the entire 
//array will be checked if they have the same letters then that word will be printed

printf("\n %lu %s\n",strlen(check),check);
printf("\n %lu %s\n",strlen(input),input);

if "happ" is inserted it should print out the last letter in the array and its size which it should be 4 but stdin "5 happ" I thought there might be a \n at the end of input so i used a temp and got the substring of input at length strlen(input)-1 but all i got was "6 happ\377" please help I tried researching it but I didnt understand what was wrong with it so I didn't know what to research


I was able to find the answer finally it was a simple fix

int cch=strlen(input-1);
if (cch > 1 && input[cch-1] == '\n')
input[cch-1] = '\0';

Need Your Help

Get index of specific value in requested JSON

jquery json

How do I get the JSON index of a specific value in my structure here? Lets say I want to know the index of "year": 2080 which would equal to index 1