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 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);<<<<<<<doesnt work
if(choice=='1'){
char input[10];
printf("%s","Enter Alphabetic Phone Number:");
fgets(input,sizeof(input),stdin);<<<<<<doesnt 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
- TheMadProfessorLv 7vor 1 JahrzehntBeste Antwort
fgets() returns a value which is a pointer to your targer ('input' in your example) or a null if no data was sent. Try enclosing each fgets in an if structure to handle the input as normal or perform appropriate error handing when a null returned.