I need to do the following
sprintf (x, "pgrep -u %s | sed %i 'q;d', y,z);
but it doesn't seem to work. Is this possible with sprintf? If so it must be some other issue in my code.
This is a discussion on Multiple variables in sprintf within the C Programming forums, part of the General Programming Boards category; I need to do the following sprintf (x, "pgrep -u %s | sed %i 'q;d', y,z); but it doesn't seem ...
I need to do the following
sprintf (x, "pgrep -u %s | sed %i 'q;d', y,z);
but it doesn't seem to work. Is this possible with sprintf? If so it must be some other issue in my code.
You only have one " character, where is your format string supposed to end?
Code:#include <stdio.h> int main(void) { char x[256]; char y[] = "foo"; int z = 3; sprintf (x, "pgrep -u %s | sed %i 'q;d'", y,z); puts(x); } /* my output: pgrep -u foo | sed 3 'q;d' */
Last edited by cwr; 02-15-2006 at 08:14 PM.
Your syntax is all screwed up there, I'm not even sure what you're trying to do. You realize you're never closing your double quotes?
Edit: cwr beat me, which is great cause I'm going to sleep anyway.![]()
Sent from my iPadŽ
Yes that's precisely what I'm trying to do. Would this be better?Originally Posted by cwr
[code]
sprintf (x, "pgrep -u %s | sed %i \'q;d\'", y,z);
[code\]
You don't need to escape the ' characters. Does my example produce the result you desire?