❓ Help C programming need help

Status
Not open for further replies.

ewe we

Elite
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.

About this Thread

  • 5
    Replies
  • 539
    Views
  • 4
    Participants
Last reply from:
Syntax code

Trending Topics

Online now

Members online
1,085
Guests online
8,893
Total visitors
9,978

Forum statistics

Threads
2,354,243
Posts
29,382,859
Members
1,079,384
Latest member
chuerys
Back
Top