hey, I'm writing a C program that simulates a "low cost" spotify, only storing names, artists, lyrics, and streams in the program
the code works fine
but there's one key issue
if I enter the input in cmd line by line, it works perfectly
if I take the input from a file, it works perfectly
but if I paste it all at the same time, it won't register the last input unless there's a whitespace after it
this is my main loop:
and in the functions themselves I do not clear the buffer unless after I get a scanf to get a choice in inner-menus
when I try to get the input with getchar() instead of scanf it just breaks the code entirely and removes first characters from longer inputs in the future, and prints the menu twice sometimes.
would appreciate some help on how to get the last input even when it isn't followed by a whitespace
TLDR : pasting multiple lines of input into cmd and it stalls when input doesn't end with whitespace
Thanks in advance to anyone helping out!
the code works fine
but there's one key issue
if I enter the input in cmd line by line, it works perfectly
if I take the input from a file, it works perfectly
but if I paste it all at the same time, it won't register the last input unless there's a whitespace after it
this is my main loop:
Code
int main() {
Playlist **playlists = NULL;
int playlistCount = 0;
int choice = 0;
do{
printMainMenu();
scanf("%d", &choice);
switch (choice) {
case 4:
{
break;
}
case 1:
{
showPlaylists(playlists, playlistCount);
break;
}
case 2:
{
addPlaylist(&playlists, &playlistCount);
break;
}
case 3:
{
deletePlaylist(&playlists, &playlistCount);
break;
}
}
}while(choice != 4);
for (int i = 0; i < playlistCount; i++) {
freePlaylist(playlists[i]);
}
free(playlists);
printf("Goodbye!\n");
return 0;
}and in the functions themselves I do not clear the buffer unless after I get a scanf to get a choice in inner-menus
when I try to get the input with getchar() instead of scanf it just breaks the code entirely and removes first characters from longer inputs in the future, and prints the menu twice sometimes.
would appreciate some help on how to get the last input even when it isn't followed by a whitespace
TLDR : pasting multiple lines of input into cmd and it stalls when input doesn't end with whitespace
Thanks in advance to anyone helping out!




![[Image: support-brown.png]](https://hackforums.net/images/hfnews/support-brown.png)