Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- int * ID;//the id of user
- char fname[10];//the first name of user
- char lname[10];//the last name of user
- int * score;//the score of user
- } users;
- users * newuser(int *ID, char fname[], char lname[], int *score) {
- char ne;
- if (ID < 0 || !lname || !fname) return NULL;
- int numID = 100;
- users * U = (users *) malloc(sizeof (users));
- U->ID = (int *) ID;
- strcpy(U->fname, fname);
- strcpy(U->lname, lname);
- U->score = (int *) score;
- int i;
- fflush(stdout);
- printf("Are you new or old user ? n if you are: new press N, old press O :n ");
- fflush(stdout);
- scanf(" %c ", &ne);
- if (ne == 'N') {
- fflush(stdout);
- printf("choose your ID, between 1 and 1000: n");
- fflush(stdout);
- scanf("%d", &ID);
- U->ID = (int *) malloc(sizeof (int));
- FILE *fp;
- fp = fopen("users.txt", "a");
- fprintf(fp, "%d", ID);
- fprintf(fp, "n");
- fclose(fp);
- }
- if (ne == 'O') {
- fflush(stdout);
- printf("Enter your ID: n");
- fflush(stdout);
- scanf("%d", &ID);
- U->ID = (int *) malloc(sizeof (int));
- FILE *fp;
- fp = fopen("users.txt", "a");
- fprintf(fp, "%d", ID);
- fprintf(fp, "n");
- fclose(fp);
- }
- fflush(stdout);
- printf("Enter your first name: ");
- fflush(stdout);
- scanf(" %s ", fname);
- fname = (char *) malloc(10 * sizeof (char));
- FILE *fp;
- fp = fopen("users.txt", "a");
- gets(fname);
- fprintf(fp, "%s", fname);
- fprintf(fp, "n");
- fclose(fp);
- fflush(stdout);
- printf("Enter your last name: ");
- fflush(stdout);
- scanf(" %s ", lname);
- lname = (char *) malloc(10 * sizeof (char));
- }
Add Comment
Please, Sign In to add comment