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

Trending Topics

Online now

Members online
1,165
Guests online
1,358
Total visitors
2,523

Forum statistics

Threads
2,293,225
Posts
29,082,494
Members
1,208,716
Latest member
infame
Back
Top