>> now my problem is i have debug error if an user key in the username or password more than 30chars.
Well here is a list of things you could be going wrong:
- the arrays your using might be too small for thirty or more characters
- if that's the case, then fgets will likely read debris you are not interested in as the password
- earlier scanf calls could cause fgets to read debris
This would be a lot easier an experience for you if you would just stop saying "Help, help! My homework is so important!" and inform us of your progress in a smart way. Code, for example, would be nice to see.
In general your whole approach to string input doesn't seem to be working. If you can't find the problem and fix it from that list, then try this.
- read into a decent sized buffer, as in a few kilobytes large
- make sure the string is the correct length
- morph the string to a uniform case
- copy from the huge temporary buffer into your smaller username and pass strings
That seems like a better approach at the moment, but do whatever you want -_-
Last edited by whiteflags; 08-17-2008 at 06:54 PM.
yea, i tried myself and complete the assignment although it tooks me alot of time and many times of failure, but feel very happy now.
i still have some question, don't worry, i m not asking you to help me complete my homework, i just want my assignment to be more perfect
my data input that prompt the user to key in is 'P123456', i use gets ( data );, i want to ask how to detect the user was type 'D123456' but not 'P123456'? how to compare and i will use printf("You key in the wrong format, please key in again");
Last edited by yrhc@eht; 08-19-2008 at 06:39 PM.
If you have string like "char data[100];", or "char *data = malloc(100);", you can check individual characters with "index" operator. In both cases, data[0] is 1st letter, data[1] second, and so on...
> i use gets ( data )
Well you should stop, and read the FAQ
Today it's "D123456"
Tomorrow is "D123456aaaaaaaaaaaaaaaaaaaa\12\34\56\78" and your box is now on a botnet owned by someone else.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
yea, i want to compare if an user input different format from D123456, i write char call_number [ 7 ];, gets ( call_number );, then i try to run the program, as an user, i key in D123456, i have debug error, what should i write the gets (call_number) so i will not have debug error even though the user has exceed the limit chararters ( D123456 ) ?
The FAQ is over here. You should take a look - it answers your questions, and possibly some others you might have at a later date.
Please look at the "why gets() is bad" article also.
It's not that we aren't here to help, but your problem is very common, so it's better to just look up the answers.
Then later, if you still have problems, then we'd be happy to fix your code.