atm959

Trouble With scanf()

Jul 17th, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.     char health;
  6.     char* name;
  7.     int xp;
  8.     int x;
  9.     int y;
  10. } Character;
  11.  
  12. int i;
  13.  
  14. int main()
  15. {
  16.     Character character;
  17.     printf("Enter a name for your character: ");
  18.     scanf("%s", &character.name); //Error
  19.     character.health = 15;
  20.     character.xp = 100000;
  21.     character.x = 10;
  22.     character.y = 10;
  23.     while(1){
  24.         displayHealth((int)character.health);
  25.         displayName(character.name);
  26.         displayExp(character.xp);
  27.         displayCharacter(character.x, character.y);
  28.         displayLocation(character.x, character.y);
  29.     }
  30.     return 0;
  31. }
  32.  
  33. void displayCharacter(int x, int y){
  34.     printf("\x1b[%d;%dH+", x + 1, y + 1);
  35. }
  36.  
  37. void displayName(char *name){
  38.     printf("\x1b[2;1HName: %s", name);
  39. }
  40.  
  41. void displayExp(int xp){
  42.     printf("\x1b[1;34HXP: %d", xp);
  43. }
  44.  
  45. void displayHealth(int health){
  46.     printf("\x1b[1;1HHealth: [");
  47.     for(i = 1; i <= health; i++){
  48.         printf("\x1b[1;%dH#", i + 9);
  49.     }
  50.     for(i = (health + 1); i <= 20; i++){
  51.         printf("\x1b[1;%dH-", i + 9);
  52.     }
  53.     printf("\x1b[1;30H]%d", health);
  54. }
  55.  
  56. void displayLocation(int x, int y){
  57.     printf("\x1b[3;1HX: %d", x);
  58.     printf("\x1b[3;10HY: %d", y);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment