The function fgets
might add a newline at the end of the string read. You’ll have to check that:
size_t ln = strlen(input) - 1;
if (input[ln] == '\n')
input[ln] = '\0';
or even
strtok(input, "\n");
More Related Contents:
- Removing trailing newline character from fgets() input
- strcmp on a line read with fgets
- read specific number of chars in c [closed]
- isnt everything where it should be, why the segmentation fault?
- How can I get a text file into a string but whith the “\n” in C?
- String manipulation in C (replace & insert characters)
- How do you allow spaces to be entered using scanf?
- How to convert an int to string in C?
- What function is to replace a substring from a string in C?
- Stringification of a macro value
- Why is “a” != “a” in C?
- Is the strrev() function not available in Linux?
- Is it possible to modify a string of char in C?
- Using strtok() in nested loops in C?
- Difference between char *str=”STRING” and char str[] = “STRING”?
- Why doesn’t scanf need an ampersand for strings and also works fine in printf (in C)?
- How do I print a non-null-terminated string using printf?
- What is the proper way of implementing a good “itoa()” function?
- string array with garbage character at end
- strstr not functioning
- Why is adding a leading space in a scanf format string recommended?
- How to read from stdin with fgets()?
- Modify a string with pointer [duplicate]
- How can I convert an int to a string in C?
- realloc(): invalid next size when reallocating to make space for strcat on char * [duplicate]
- Reading from file using fgets
- How to fgets() a specific line from a file in C?
- split char string with multi-character delimiter in C
- Assign string to element in structure in C
- Assigning char array a value in C