Find the answer to your Linux question:
Results 1 to 2 of 2
Hi! I am new to programming in c. I can write hello world, but want to eventually move up to a text based rpg. I am working on the character ...
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    7

    scanf help

    Hi! I am new to programming in c. I can write hello world, but want to eventually move up to a text based rpg. I am working on the character creation script, but it isn't saving the variables correctly. Please tell me what is wrong with my code.
    //Character Creation
    #include <stdio.h>

    main()
    {
    char name, race, class, age, weapon, area, answer;

    printf("Please write all input as lowercase, except for name and area, and on age please spell the numebr\n");

    //Trial 1
    puts("Choose your name: ");
    scanf("%s", &name);
    puts("Choose your race:\nDwarf\nElf\nHalf-Elf\nHuman\nOrc ");
    scanf("%s", &race);
    puts("Choose your class:\nFighter\nMage\nRanger ");
    scanf("%s", &class);
    puts("What is your age: ");
    scanf("%s", &age);
    puts("Choose your weapon:\nSword\nSpell Book\nBow ");
    scanf("%s", &weapon);
    puts("Where do you live:\nElixia\nDragoda\nThe Temple City ");
    scanf("%s", &area);
    puts("Are all of these correct? ");
    scanf("%s", &answer);

    if(answer == "no")
    puts("Choose your name: ");
    scanf("%s", &name);
    puts("Choose your race:\nDwarf\nElf\nHalf-Elf\nHuman\nOrc ");
    scanf("%s", &race);
    puts("Choose your class:\nFighter\nMage\nRanger ");
    scanf("%s", &class);
    puts("What is your age: ");
    scanf("%s", &age);
    puts("Choose your weapon:\nSword\nSpell Book\nBow ");
    scanf("%s", &weapon);
    puts("Where do you live:\nElixia\nDragoda\nThe Temple City ");
    scanf("%s", &area);
    puts("Are all of these correct? ");
    scanf("%s", &answer);

    if(answer == "yes")
    printf("So %s, you are a %s year old %s %s who lives in %s and uses a %s\n", &name, &age, &race, &class, &area, &weapon);
    }

    What appears when i try to compile it:
    firstwrite.c: In function ‘main’:
    firstwrite.c:26:11: warning: comparison between pointer and integer
    firstwrite.c:42:11: warning: comparison between pointer and integer
    Last edited by Aramil; 10-16-2011 at 12:18 AM.

  2. #2
    Just Joined!
    Join Date
    Oct 2011
    Posts
    7
    I don't understand why it says that because I only use the char variable type

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •