Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C programming help fgets?

C programming fgets help please?

I am given assessment to use fget(not scanf or anything else)I made a menu and when I want to enter a choice fgets doesnt work, it shows error. I am working on it for 5 hours still didnt get it. Even it has not mentioned in textbook in detail about fgets. and

int main(void)

{

int optionStats[NUM_OPTION_STATS];

char choice;

do

{

printf("Menu\n\n");

printf("1. Translating alphabetic number\n");

printf("2. Fibonacci numbers\n");

printf("3. Sort\n");

printf("4. Find substrings\n");

printf("5. Session summary\n");

printf("3. Bushfire\n");

printf("6. Exit\n");

printf("7. Go Again\n");

printf("Enter your chose: ");

fgets(choice,size(choice),stdin);

fgets(choice,sizeof(choice),stdin);<<<<<… work

if(choice=='1'){

char input[10];

printf("%s","Enter Alphabetic Phone Number:");

fgets(input,sizeof(input),stdin);<<<<<… work at all

translateNumber(0, input);

char c[1];

printf("\nPress enter to continue..");

fgets(c,1,stdin); <<<doesnt work

}

while(choice!='7')

1 Answer

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Change the line which says:

    "char choice;"

    to

    "char choice[10];"

    You want a pointer to an array of characters for fgets(), not one character itself.

Still have questions? Get your answers by asking now.