Created
April 14, 2019 16:44
-
-
Save sewera/d00280201d9cf1604f24922204630dbd to your computer and use it in GitHub Desktop.
Example of removing newlines from buffer
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
void append_song_head(Song **head_ref) { | |
/** | |
* User interface for appending a new node. | |
*/ | |
// Variables used in adding a new node | |
char artist[CHAR_LIMIT]; | |
char album[CHAR_LIMIT]; | |
char title[CHAR_LIMIT]; | |
char year[6]; | |
char duration_m[10]; | |
char duration_s[10]; | |
printf("Add a song\n"); | |
printf("Artist: "); | |
fgets(artist, CHAR_LIMIT, stdin); | |
artist[strcspn(artist, "\n")] = '\0'; // removing newline characters from the input string | |
printf("Album: "); | |
fgets(album, CHAR_LIMIT, stdin); | |
album[strcspn(album, "\n")] = '\0'; | |
printf("Title: "); | |
fgets(title, CHAR_LIMIT, stdin); | |
title[strcspn(title, "\n")] = '\0'; | |
printf("Year: "); | |
fgets(year, 6, stdin); | |
printf("Duration (minutes): "); | |
fgets(duration_m, 10, stdin); | |
printf("Duration (seconds): "); | |
fgets(duration_s, 10, stdin); | |
append( | |
head_ref, | |
artist, | |
album, | |
title, | |
atoi(year), | |
(unsigned char) atoi(duration_m), | |
(unsigned char) atoi(duration_s) | |
); | |
printf("[I] Song added.\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment