LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2010, 09:49 AM   #1
paliga
Member
 
Registered: Feb 2010
Posts: 39

Rep: Reputation: 0
Output a C variable with a shell command


Hi...

the following does not work... Im pretty new to C... have no clue what to do.. :/

#include <stdio.h>
main()
{
char variable[]="Hello world\n";
system(sprintf("echo %s > /tmp/output", variable));
}

thanks in advance for any suggestions : )

k.
 
Old 07-19-2010, 10:20 AM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Look up what sprintf actually does,what it operates on,what it returns and it's passed arguments. Then look at what system expects and what you're giving it.
 
Old 07-19-2010, 11:16 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by bgeddy View Post
Look up what sprintf actually does,what it operates on,what it returns and it's passed arguments. Then look at what system expects and what you're giving it.
Just to reiterate what you are saying:

based on which clauses of 'man 3 sprintf' the code is supposed to work ?
 
Old 07-20-2010, 01:50 AM   #4
paliga
Member
 
Registered: Feb 2010
Posts: 39

Original Poster
Rep: Reputation: 0
hmmm...

man 3 sprintf...

and

man sprintf...

give me an

No manual entry for sprintf

...
 
Old 07-20-2010, 06:10 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I don't see where it says what distribution of Linux you have, so I can't tell you the commands needed to install the missing man pages. But documentation for functions in the C standard library is available all over the net.

Here is a nice version of the documentation pages you want
http://www.cplusplus.com/reference/c...stdio/sprintf/
http://www.cplusplus.com/reference/c...stdlib/system/

Don't get worried that the website is C++ documentation. Those pages are C documentation.

Last edited by johnsfine; 07-20-2010 at 06:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script: saving output from command into a variable grcunning Linux - Newbie 7 01-26-2010 11:43 AM
csh Shell Script: Getting wc command output to variable to do math on it, how? vxc69 Programming 5 05-04-2009 04:31 PM
Write output or command to variable (shell) kernel_geek Programming 9 03-12-2007 04:45 AM
shell scipting: append output of a command to a variable jonhewer Linux - Newbie 10 08-24-2005 05:42 AM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration