Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

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 Antwort

Relevanz
  • Anonym
    vor 1 Jahrzehnt
    Beste Antwort

    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.

Haben Sie noch Fragen? Jetzt beantworten lassen.