Created
April 24, 2013 15:05
-
-
Save TheCodeEngine/5452848 to your computer and use it in GitHub Desktop.
C Delete the new line character from the end of a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| void string_removeNewlineAtEnd(char *string) | |
| { | |
| if ( string[strlen(string) - 1] == '\n' ) | |
| string[strlen(string) - 1] = '\0'; | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| char name[80]; | |
| fgets(name, sizeof(name), stdin); | |
| string_removeNewlineAtEnd(name); | |
| fprintf(stdofut, "String: %s\n", name); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment