LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 03-24-2005, 11:47 PM   #1
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
How to import arguments to system() function


I need to create a iso fs using a C pgm. I can do it juz by calling system("mkisofs ---"); but how I can make it user interactive by providing arguments(variables) to this function
 
Old 03-25-2005, 12:33 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Try something as follows:
Code:
char s[100];
char cmd[200];

...
gets(s);
....
fprintf(cmd,"mkisofs %s",s);
...
system(cmd);
 
Old 03-25-2005, 06:35 AM   #3
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Original Poster
Rep: Reputation: 15
Thanx nixcraft,

But I 've got a problem.
A warning message like
" passing arg 1 of fprintf from incompatible pointer type " is displayed and the pgm problably is not working.
How to fix it out.
 
Old 03-25-2005, 08:05 AM   #4
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Actually, you'd want to use sprintf, not fprintf. fprintf is for printing to file handles/streams. Secondly, when getting user input, one should never use an input routine that does not restrict the # of chars the user is allowed to enter.
Code:
  char s[100];
  
  gets(s);  // WRONG
  fgets(s, 99, stdin); // RIGHT
And finally, don't use system. Use popen.

One reason for this is in the system man page:
Quote:
During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.
 
Old 03-25-2005, 08:12 AM   #5
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Opps it should be sprintf and not fprintf sorry...
here is the right one

Code:
#include<stdio.h>
main()
{
   char s[100];
   char cmd[200];
   printf("Enter arg : ");
   fgets(s,100,stdin);
   sprintf(cmd,"ls %s",s);
   system(cmd);
}
 
Old 03-25-2005, 08:49 PM   #6
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Original Poster
Rep: Reputation: 15
Thanx for u all,

It did really work
 
  


Reply



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
How to pass structure as function arguments ssg14j Programming 2 08-20-2005 09:59 PM
Passing Arguments into the Thread Function George_gk Programming 2 01-31-2005 05:03 AM
Arguments in PHP function declaration Parksy Programming 5 07-04-2004 04:22 PM
C Function Arguments jpbarto Programming 6 04-23-2004 01:59 PM
Function accept() and its arguments. krajzega Programming 1 01-20-2004 01:26 AM

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

All times are GMT -5. The time now is 05:54 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