0

Hi, I'm having a minor problem with output with printf. I understand you escape % in printf with %% so if I had some string it would be

printf("%%eax");

But if I have

printf("%%%s", registers(C));

I get an an output of %%eax, which is one too many percent signs. I tried it with just %%s but I'm stil getting an error. Is there any way around this? Thanks.

3
Contributors
4
Replies
26
Views
4 Years
Discussion Span
Last Post by nullptr
0

What compiler are you using?
Seeing as printf("%%%s", registers(C)) isn't working as expected, you may need to resort to a workaround like printf("%s%s", "%", registers(C))

0

I'm using C90 if that's what you mean.
I tried your solution, but it still gave me a weird answer.

registers(d) returns a char* so it returned %ebp

So the actual answer it gave me was:
%%ebp %ebp

Which should just be
%ebp

EDIT:
Sorry I'm an idiot. It didn't output %%ebp %ebp
But it still returns %%ebp

Edited by Na'Vi: I'm dumb

0

Can you provide us with the code you have for the registers() function? Perhaps the reason you're getting an extra percent sign is because your function is tacking it on automatically. If it's not, I would have a reason to believe there's something wrong with your compiler because when I do printf("%%%s", "eax"), I'm getting the expected output of "%eax".

Also, C90 isn't a compiler, it's a language standard from around 1990. We're on C11 now.

Edited by Tumlee

0

registers(d) returns a char* so it returned %ebp

It could well be as Tumlee suggested.
If registers(d) is already returning %ebp, then you only need printf("%s", registers(d))

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.