C examples for File:Text File
fgets( ) does not remove the newline character and gets_s( ) does,
So you will have to manually remove it.
#include <stdio.h> #include <string.h> int main(void) { char str[80];/*w w w . j a va2s .com*/ int i; printf("Enter a string: "); fgets(str, 10, stdin); /* remove newline, if present */ i = strlen(str) - 1; if (str[i] == '\n') str[i] = '\0'; printf("This is your string: %s", str); return 0; }