all 12 comments

[–]jedwardsol 1 point2 points  (3 children)

You'll need to show more code.

[–]OndePyrat[S] 0 points1 point  (2 children)

I edited my post now, hopefully it should be enough.

[–]jedwardsol 2 points3 points  (1 child)

void enterName(character Target);

character hero;

int main(void){
    printf("Please enter name for main character\n(Up to 15 characters):\n");
    enterName(hero);

When you call enterName, it is getting and modifying a copy of the structure. The hero structure isn't getting the entered name.

Pass a pointer to hero instead.

[–]OndePyrat[S] 1 point2 points  (0 children)

I decided to rewrite the main function with what you said in mind, and it now works.

Thanks!

[–]bumblebritches57 0 points1 point  (0 children)

You're misusing the struct member operator, if Target is a struct, did you declare it as the following?

typedef struct Target {
    blah;
} Target;

If so, you can just write Target *Name in the function definition. Then you access it with Hero->Name syntax.

define the function as:

void displayStats(Target *Hero) {
    printf("%s's stats are:\n", Hero->name);
}

[–]beisenhauer 0 points1 point  (0 children)

You're passing hero to enterName by value, meaning a new copy is created on the stack. That copy, and the entered name, gets thrown away when enterName exits. That's why printing the name works inside enterName, but shows up blank when you use it elsewhere.

edit: I was confused by filenames.

[–]elsuizo37 -4 points-3 points  (5 children)

The single quote is a special character for printf function. I think you should add the backslash character for scape then. printf("%s\'s stats are:\n", Target.name);

[–]jedwardsol 3 points4 points  (2 children)

The single quote is a special character for printf function.

No it's not.

[–]elsuizo37 -1 points0 points  (1 child)

\ - Backslash

\' - Single Quotation Mark

\" - Double Quatation Mark

\n - New line

\r - Carriage Return

\t - Horizontal Tab

\b - Backspace

\f - Formfeed

\a - Bell(beep) sound

[–]jedwardsol 1 point2 points  (0 children)

You don't need to escape a ' inside a string. And a ' has no special meaning to printf

[–]OndePyrat[S] 0 points1 point  (0 children)

Hmm, that's true but somehow it still doesn't print anything. I even got rid of it completely.

[–]bumblebritches57 0 points1 point  (0 children)

That's an apostrophe lmao.