License Public Domain
Lines 12
Keywords
fgets (1) newline (1) stdio (1) string (7)
Permissions
Owner: schram
Viewable by Everyone
Editable by All Siafoo Users
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

Get String Without Newline Atom Feed 0

In Brief fgetstr() is a function that mimics the behavior of fgets(), but removes new-line character at end of line if it exists. Safe to use whenever fgets is safe to use.
# 's
 1//fgetstr() - mimics behavior of fgets(), but removes new-line
2// character at end of line if it exists
3char *fgetstr(char *string, int n, FILE *stream)
4{
5 char *result;
6 result = fgets(string, n, stream);
7 if(!result)
8 return(result);
9
10 if(string[strlen(string) - 1] == '\n')
11 string[strlen(string) - 1] = 0;
12
13 return(string);
14}

fgetstr() is a function that mimics the behavior of fgets(), but removes new-line character at end of line if it exists. Safe to use whenever fgets is safe to use.