❓ 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
  • 490
    Views
  • 4
    Participants
Last reply from:
Syntax code

Online now

Members online
1,025
Guests online
692
Total visitors
1,717

Forum statistics

Threads
2,276,966
Posts
28,973,387
Members
1,229,669
Latest member
zeeeee345
Back
Top