Last active
August 29, 2015 13:57
-
-
Save vampy/9451253 to your computer and use it in GitHub Desktop.
This file contains 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
// Read a certain number of character from the keyboard | |
// put it in *string | |
// return the number of characters read | |
int read_string(char *string, int read_length) | |
{ | |
char read_char; | |
int i = 0; | |
// weird case when we have \n on our first character | |
if((read_char = getchar()) != '\n') | |
{ | |
// not special case | |
string[i] = read_char; | |
i++; | |
} | |
while ((read_char = getchar()) != '\n' && i < read_length) | |
{ | |
string[i] = read_char; | |
i++; | |
} | |
// put last character | |
string[i] = '\0'; | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment