Thread: Read from file and match the password and username

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    10

    Question Read from file and match the password and username

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
       FILE *dg;
       int No1,No2;
       int username,password;
     
       if( (dg=fopen("ogr.txt","r")) == NULL )
         puts("File can not open !\n"), exit(1);
      
       printf("type username :"); scanf("%d",&username); printf("\n");
       printf("type password :"); scanf("%d",&password); printf("\n");
      
    
       while( !feof(dg) )                  
       {
          fscanf(dg,"%d %d",&No1,&No2);
    
          if((No1==username) && (No2==password))
          {
             printf("Correct Numbers");
          }
          else
          {
             printf("Wrong Numbers");
          }
       }
    
       fclose(dg);                          
    
     return 0;
    }
    error message :
    ubuntu@ubuntu-desktop:~/Desktop/Debug$ cc readf.c -o 5
    readf.c: In function 'main':
    readf.c:22: error: stray '\302' in program
    readf.c:22: error: stray '\240' in program

    ogr.txt
    22 45
    18 88
    94 79
    46 92
    31 0
    98 73
    55 0
    25 54
    65 38
    45 77

    if I cancel this part if((No1==username) && (No2==password))
    code is working, what can be the errors?

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I believe that stray /something means an illegal character. Usually from copying pasting.
    Try typing again the line.
    Read also the FAQ about feof()

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    One of those symbols is not as they appear, then, in your source file. If I remember correctly, those \xxx things are actually octal, but anyway they represent special characters.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    Thnx for urgent reply

    I will change the algortihm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading from external file
    By djayz in forum C Programming
    Replies: 13
    Last Post: 03-24-2005, 01:15 PM