What's new

Help C programming need help

Status
Not open for further replies.

medesjv25

Forum Veteran
Joined
Feb 21, 2018
Posts
1,824
Solutions
1
Reaction
473
Points
708
Pano po mag validate ng name sa c? Yung pag po nag lagay ng name titingnan kung tama yung name o mali..
sinubukan ko po kac

if(inputname==name)

Parang log in po.. Username saka sa password.. Pwedi po ba yun sa c? Yung sa password po number naman.. Pero kac yung sa username characters

ayaw.. Ano po ba dapat? Paturo po..
 
Here short and dirty.

C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct User_pass {
    char name[20];
    char password[20];
};

int main(void) {
    size_t nbytes = 1;
    char *my_string = malloc(nbytes+1);
    char *my_input = malloc(nbytes+1);
    printf("\nProgram that accepts and validate input\n");
    printf("---------------------------------------\n");
    printf("\nEnter name: ");
    getline(&my_string, &nbytes, stdin);
    sscanf(my_string, "%s", my_input);
    struct User_pass user_pass;
    strcpy(user_pass.name, "myname");
    strcpy(user_pass.password, "123");

    if (strcmp(my_input, user_pass.name) == 0) {
        printf("Now enter the password: ");
        getline(&my_string, &nbytes, stdin);
        sscanf(my_string, "%s", my_input);
        if (strcmp(my_input, user_pass.password) == 0) {
            printf("\nLogin successful!\n");
        } else {
            printf("\nINCORRECT PASSWORD!\n");
        }

    } else {
        printf("Username not found!\n");
    }

    return 0;
}
 
Status
Not open for further replies.

Similar threads

Back
Top