![]() |
program terminates at fgets();
Dear all,
i am trying to make a scheduler program. so in the following code the part where Code:
if(op == 2) in this part i ask for a description of the appointment, the start time and the duration. to ask for the description, i am using the fgets(); function. but the program terminates at this point saying "schedule.exe has stopped working". this entire part is inside the main, inside an infinite loop like this Code:
for your reference Code:
struct appointments Code:
int add(struct appointments appo[24],char desc[100],int start_h,int dur) |
Re: program terminates at fgets();
dear all,
i have used the trial and error method to solve the above problem. the code below works just as i expected.however i did am not writing to any file in this program. maybe i will try that later. for now it works when the program is running. I DON'T UNDERSTAND HOW THE ABOVE DID NOT WORK. i have put the SCANF(); before the fgets(); and it magically worked. can anyone please tell me why the above did now work but the following did. THANKS A LOT. please just run this code. Code:
#include<stdio.h> |
Re: program terminates at fgets();
Difficult to say. scanf is a very confusing function, if you don't know *exactly* what's going on (which is common for a learner) and it goes wrong, it can be very difficult to determine why.
I suggest you drop scanf and use fgets to read a line of input from the user, then parse that line to get the data you want. So if the data is in the form "description,value 1,value 2" then you can split it at the commas and copy the bits between the commas to various variables. So for example if you replace commas with \0 bytes and store the address plus one of those bytes into, say, ptrarray[], then you can do: Code:
strcpy(appo[0].desc, ptrarray[0]); // which would be the same as the start address of the string |
| All times are GMT +5.5. The time now is 23:14. |