Thread: Help in checking password in a file

  1. #61
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Quote Originally Posted by frodonet View Post
    but earlier before i do scanf i have put these command.

    Code:
    fpassword = fopen("C:\\PASSWD.TXT", "r");
    if (fpassword == NULL) printf("File doesn't exist\n");
    but if it can't open in the first place...shouldn't it terminate instantly?? rather than continue executing...
    Yes, it should, but your program doesn't. Again, it related to what I told you before about code execution always go forward because you haven't told the compiler to quit.

  2. #62
    Registered User
    Join Date
    Sep 2007
    Posts
    45
    Quote Originally Posted by matsp View Post
    Because there is a newline at the end of "John1" that is printed as part of the username, then a comma after the username, which comes out on the next line, before the password. You probably want to remove those. I posted a post earlier about how to remove the newline after fgets().

    --
    Mats
    ok i have remove the new line though...

    but after scanf...it seems it still close the program...i don know why....

    argghhghghgh

  3. #63
    Registered User
    Join Date
    Sep 2007
    Posts
    45
    Quote Originally Posted by Elysia View Post
    Yes, it should, but your program doesn't. Again, it related to what I told you before about code execution always go forward because you haven't told the compiler to quit.
    in which part i don tell the compiler to quit???

  4. #64
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Quote Originally Posted by frodonet View Post
    in which part i don tell the compiler to quit???
    After checking the file failed to open.

  5. #65
    Registered User
    Join Date
    Sep 2007
    Posts
    14
    Code:
    #include <stdio.h>
    #include <io.h>
    #define NULL 0
    #define EOF (-1)
    
    main()
    {
    	char pw[4];
    	char c;
    	FILE *fp, *fopen();
    	fp=fopen("c:\\password.txt","rb");
    
    	if(fp==NULL)
    	{
    
    	printf("can not open file\n\n");
    
    	getchar();
    
    	exit();
    
    	}
    
    
    
    
    	while((c=fgetc(fp))!=(EOF))
    	{
    	/* printf("found\n"); */
    	printf("&#37;c", c);
    
    	getchar();
    	}
    
    	fclose(fp);
    
    
    	getchar();
     }
    hi...i recently given sort of assignment for matching.
    but i facing problem for stopping.

    As i use getchar() to troubleshoot, instead i can read the password.txt
    but read with never ending...can someone enlighten me plz..?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM