Guest User

Untitled

a guest
May 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. typedef struct {
  2. int * ID;//the id of user
  3. char fname[10];//the first name of user
  4. char lname[10];//the last name of user
  5. int * score;//the score of user
  6.  
  7. } users;
  8.  
  9. users * newuser(int *ID, char fname[], char lname[], int *score) {
  10.  
  11. char ne;
  12. if (ID < 0 || !lname || !fname) return NULL;
  13. int numID = 100;
  14.  
  15. users * U = (users *) malloc(sizeof (users));
  16.  
  17.  
  18. U->ID = (int *) ID;
  19. strcpy(U->fname, fname);
  20. strcpy(U->lname, lname);
  21. U->score = (int *) score;
  22.  
  23.  
  24. int i;
  25.  
  26. fflush(stdout);
  27. printf("Are you new or old user ? n if you are: new press N, old press O :n ");
  28. fflush(stdout);
  29. scanf(" %c ", &ne);
  30.  
  31.  
  32.  
  33.  
  34. if (ne == 'N') {
  35. fflush(stdout);
  36. printf("choose your ID, between 1 and 1000: n");
  37. fflush(stdout);
  38. scanf("%d", &ID);
  39. U->ID = (int *) malloc(sizeof (int));
  40.  
  41. FILE *fp;
  42. fp = fopen("users.txt", "a");
  43.  
  44.  
  45. fprintf(fp, "%d", ID);
  46.  
  47. fprintf(fp, "n");
  48. fclose(fp);
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }
  55. if (ne == 'O') {
  56. fflush(stdout);
  57. printf("Enter your ID: n");
  58. fflush(stdout);
  59. scanf("%d", &ID);
  60. U->ID = (int *) malloc(sizeof (int));
  61.  
  62. FILE *fp;
  63.  
  64. fp = fopen("users.txt", "a");
  65.  
  66.  
  67. fprintf(fp, "%d", ID);
  68.  
  69. fprintf(fp, "n");
  70. fclose(fp);
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77. fflush(stdout);
  78. printf("Enter your first name: ");
  79. fflush(stdout);
  80. scanf(" %s ", fname);
  81. fname = (char *) malloc(10 * sizeof (char));
  82.  
  83. FILE *fp;
  84.  
  85. fp = fopen("users.txt", "a");
  86.  
  87. gets(fname);
  88. fprintf(fp, "%s", fname);
  89.  
  90. fprintf(fp, "n");
  91. fclose(fp);
  92.  
  93. fflush(stdout);
  94. printf("Enter your last name: ");
  95. fflush(stdout);
  96. scanf(" %s ", lname);
  97. lname = (char *) malloc(10 * sizeof (char));
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. }
Add Comment
Please, Sign In to add comment