Main Properties
Lesson 2 of 8 in Coddy's User Class - OOP Project course.
Challenge
EasyThe User class should have two main properties:
usernameemail
These properties are passed to the constructor and are public (it is possible to access them).
Add the main constructor to the User class.
Try it yourself
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "user.h"
int main() {
User u;
User_init(&u, "", "");
char line[1024];
while (fgets(line, sizeof(line), stdin)) {
line[strcspn(line, "\r\n")] = '\0';
char* cmd = strtok(line, " \t");
if (!cmd) continue;
if (strcmp(cmd, "new") == 0) {
char* un = strtok(NULL, " \t");
char* em = strtok(NULL, " \t");
User_init(&u, un ? un : "", em ? em : "");
}
if (strcmp(cmd, "username") == 0) { printf("%s\n", u.username); }
if (strcmp(cmd, "email") == 0) { printf("%s\n", u.email); }
}
return 0;
}