M medesjv25 Forum Veteran Joined Feb 21, 2018 Posts 1,832 Solutions 1 Reaction 474 Points 664 Dec 6, 2019 #1 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..
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..
M medesjv25 Forum Veteran Dec 6, 2019 TS TS #3 Arcturus said: Gawin mong string yung username Click to expand... Patingin po ng codes
H homer_simpson Eternal Poster Dec 6, 2019 #5 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; }
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; }