Results 1 to 6 of 6
HI! In the program I am writing, it gives commands based on what the value of the variable is. In this case all values are completely text (no integers) and ...
- 10-16-2011 #1Just Joined!
- Join Date
- Oct 2011
- Posts
- 7
string help
HI! In the program I am writing, it gives commands based on what the value of the variable is. In this case all values are completely text (no integers) and I can't think of what to use besides if. I have tried for, else, while, ans else-if with no luck. Thank you.
- 10-16-2011 #2Just Joined!
- Join Date
- Apr 2011
- Posts
- 87
let me see your code
- 10-16-2011 #3Just Joined!
- Join Date
- Oct 2011
- Posts
- 7
//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);
}
- 10-16-2011 #4Linux Newbie
- Join Date
- Dec 2009
- Posts
- 241
Hi,
to tell you the truth, I hardly can C.
Here some errors I can figure you:
Will declare these Values are single characters.Code:char name, race, class, age, weapon, area, answer;
They can just store one digit.
Will store the information into the position where name points.Code:scanf("%s", &name);
So let's assume name has the value 0.
Since it ain't initialized it can have any value between 0 and 255.
So you will write a string into the memory assigned to your program position 0.
You are not changing the value of name.
You should check out a tutorial for C explaining pointers and arrays!
- 10-16-2011 #5Just Joined!
- Join Date
- Oct 2011
- Posts
- 7
thank you
Thank you this helps. I can't find a site that will teach me how to write in c beyond hello world do you know of any?
- 10-16-2011 #6Linux Newbie
- Join Date
- Dec 2009
- Posts
- 241
Hi guess that one is fine for the moment:
A Tutorial on Pointers and Arrays in C
Or that one:
Pointers - C++ Documentation


Reply With Quote
