fgets is not taking input from keyboard after one input in centos 7.5
hi to all,
i've centos7.5 and codeblocks 17.12 in VM i am building a programm for date manipulation. shared library for this is OK. but in main file where I called these functins having problem when I tried to input for two dates ( date1 and date2 ),date1 is getting input well but date2 is skipped automatically. I am not gettiing how to get input for date2. pleaase help.code for validity and cmpDate is in lib file. Code:
#include <stdio.h> Code:
int isValid(char *date) Code:
int cmpDate(char *date1, char *date2) |
Quote:
And again, after asking about codeblocks/C programming for eight years...surely you have made SOME progress: https://www.linuxquestions.org/quest...7/#post5837681 Even more odd that you're flushing the input buffer, right after you're asking for the second date, and seem surprised when it's empty. |
The very first problem that you don't check buffer after fgets: if the line was longer that net 9 bytes (brt 11: don't forget \n and \0), then issue a warning, otherwise remove the \n
example: https://stackoverflow.com/questions/...om-fgets-input |
i removed line
Code:
Code:
[rahul@client1ora11gr2 Debug]$ ./datemain |
Feel free to read my previous post.
|
i found there is no trailing new line or carrige return, at the end there is 0 (NULL); and still it is not taking input from second fgets
Code:
[rahul@client1ora11gr2 Debug]$ ./datemain |
check your logic for case2: in main. "Comments" hints within code
Code:
#include <stdio.h> |
> I found there is no trailing new line
That means the buffer is too small for the line; the rest will be returned by the next fgets. Kindly read my first post: the buffer should be big enough for the complete line plus \n plus \0 |
gets is not taking input from keyboard
as it looks like you're asking user for input then using a file to get what you're asking for off the cli.
Just a little bit of code, Taking NevemTeve guidance he is trying to get across to you in declaring a size big enough for the data, plus end line and null (?), and having a few too many does not hurt either. Because it gets terminated at the end if you do it properly. Swiping some code off the net and modifying it into a function, and making it work like this, then calling it from main, if you compile it then run it you'll see how this works. getting off cli then processing it, then with the proper data returned, you can use it in a switch/case statement. uses pointers without the use of malloc. Code:
#include <stdio.h> if you are asking for user input, then why are you opening files that make no sense /dev/tty to check for a date? Here " is skipped automatically. I am not gettiing how to get input for date2. pleaase help." Code:
yes, it is not your original code, I redid some of it and got it working. your functions too, the comparisons are wrong as well in isValid function. I'm contemplating whether or not I should post all of it and point out some stuff. all of the mistakes actually. but I still do not know what the opening of files is doing for you when you're asking for input off the command line. |
I went looking for
dtmanip.h because I got curious, then found this https://github.com/sunilsp77/Date-Ma.../master/Main.c are you trying to write this in your "own words" because it is doing what you're trying to do, with a lot more doing to the date, using dtmanip.h with the same basic setup. It is find by me because it looks like you're actually trying to figure out something. |
All times are GMT -5. The time now is 09:32 AM. |