Wait, I doubt whether this program will correctly terminate on every machine, it appears that it won't, because you're using
void main() , the standard says that you must use
int main() and not void main() (
void main() is evil!!)
Further you're not using code tags (you should, as described in the
forum announcement about code tags, so please use code-tags from now on).
Hmm... What else can I comment on?
Well, you're making use of an unportable library called
conio.h but for what purpose? Only to ask for a key press just before the program closes? You could use the
getchar() function instead of conio's
getch() , so you can make your code portable.
what was wrong in this code, Its taking the username but its not properly taking the input of password.
Well, you want to store a username into a character variable, a character variable is only capable of holding one character, not a sequence of characters. If you want to store a sequence of characters, you should use a character array (aka: C-string), a character array is declared like this:
The above code reserves space for storing a username which can consist out of a maximum of 49 characters (remember: the last character is always used to store the nul-terminator)
Now you can get the username by using
scanf like this:
More info about character arrays and the scanf-function can be found at the links which are at the bottom* of this post.
And my another doubt is how can i use string for this program instead of character so that i can give big names for username and password.
give me a complete program using strings and adding file operations so that i can save the information and use them again and again to login.
No, this doesn't conform to Daniweb's homework policy, we don't give free code here, we only provide you paths to the solution, not the entire solution itself.
* - This information should get you started:
http://www.cplusplus.com/doc/tutorial/ntcs/
http://www.cplusplus.com/reference/c.../cstdio/scanf/
http://www.cplusplus.com/reference/c...stdio/getchar/