tags:

views:

67

answers:

2

I am writing a fuzzer that using the system() function and I need to copy:

char a[1100]; /* full of A's with null ending */

into:

char tmp[10000];

I used:

sprintf(tmp, "%s", a);

When I printf tmp there is nothing printed. What am I doing wrong?

+3  A: 

There's no way to say what you are doing wrong without seeing the whole thing.

The above sprintf should work, although strcpy would make more sense for that purpose. I'd guess that sprintf works fine. Could be that your a array is not "full of A's" as you believe, but rather an empty string (full of zeros). Or maybe it is your printing that either doesn't work or it works but you don't see the output for some reason.

My bet would be that your a is an empty string. No A's there. Where and how do you put those A's into the a array?

AndreyT
I found out that memset() wouldn't fill my variable if its declared in the main function. Is there a reason for this? I thought that I should avoid declaring variables outside of the stack.
Dan
you can use memset on any variable of appropriate size regardless where the variable is declared, must be some other issue.
Anders K.
@Dan: Huh? Show us your code.
jamesdlin
+3  A: 

Output is often line-buffered. If the string you're printing has no newline, you might not see it without calling fflush first (also see http://c-faq.com/stdio/fflush.html). But as AndreyT said, we can't tell without seeing the rest of your code.

jamesdlin