Scanning a string until a newline is occurred

I'm aware that using scanf("%[^\n]s",str) will read the string until \n occurs but when I run this code, scanf is not reading anything from stdin but it rather throws junk value when printf is executed, but if I replace the scanf with scanf("%s",str) then it works correctly, i.e stores first word in str. If I scan it outside the switch then it works fine, I guess the problem is with the first scanf.

I've tried using fgets, gets, fgets_s, gets_s but none of them works either. Please can someone tell me why is it happening? And how to fix this? I'm sorry if this question is too basic.

#include<stdio.h>
int main(void)
{
    while (1)
    {
        char choice;
        char name[80];  
        fflush(stdin);
        scanf("%c",&choice);
        switch (choice)
        {
            case 'i':
            fflush(stdin);
            scanf("%[^\n]s",name); /*this is bugging me, replace it with scanf("%s",name); it will work fine.*/
            printf("%s",name);  
            break;
        }
    }
}