lundi 2 mars 2015

fgets() problems with user input



So I am making a heap implemented to do list application with a menu driven interface. One of the options is to add a task to the list. The variables taskResponse and priorityResponse are both type char. priorityR is a an int converted from fgets(&priorityResponse,128,stdin). (128 is the max string length for user input in the application). I know the functions create task and addHeap are working correctly. The issue is that when running, the first fgets() call does not seem to retrieve user input and assign it to the taskResponse variable, but the second fgets() call works perfectly fine and assigns user input to priorityResponse variable just fine. Would anybody know why the first fgets() call is not working properly?



case 'a':
printf("Please Enter the name of the task\n>");
fgets(&taskResponse,128,stdin);
printf("Please Enter the priority of the task\n>");
fgets(&priorityResponse,128,stdin);
priorityR = atoi(&priorityResponse);
newTask = createTask(priorityR,&taskResponse);
addHeap(mainList,newTask,compare);
printf("Done\n");
break;



Aucun commentaire:

Enregistrer un commentaire