Thread: Simple login program - Crashes :(

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    93

    Simple login program - Crashes :(

    HI guys,

    This is my code:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #define name1 "denny"
    #define pass1 "123"
    
    int main(int argc, char *argv[])
    {  
        char * name;
        char * pass;
    
        if(argc != 3)
        {        
            printf("Usage: login Your_Username Your_Password\n");
        scanf(argv[1],"%s", &name); // to read username argument
        scanf(argv[2],"%s", &pass; // to read password argument
    
        }
    
        name = argv[1];
        pass = argv[2];    
    
        if(strcmp(name,name1) == 0 && strcmp(pass,pass1) == 0)
           printf("Correct username and password\n");
        else
           printf("Wrong username and password\n");
    
        return 0;
    }
    Im very new to C coding, but I was kind of hoping this would work and it doesnt! It crashed the program and says it cant debug. Can anyone help me.

    James

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Learn what scanf does, or at least the parameters it is expecting:
    http://www.cplusplus.com/reference/c...dio/scanf.html

    Your name and pass character pointers don't point anywhere. You should point them at the arguments you are trying to use as comparison.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. funcion runs 14 times, then program crashes
    By happyclown in forum C Programming
    Replies: 9
    Last Post: 03-03-2009, 11:58 PM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM