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 04-12-2009, 06:15 AM   #1
netpumber
Member
 
Registered: Sep 2007
Location: In My Box
Distribution: Arch Linux
Posts: 423

Rep: Reputation: 33
[C] system command


Hi guyz... finally i write this script i c.

how you see it? does it have any mistakes? I m new in programming so...

Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{

char counter;
char dname;
counter = "y";

do {
printf( "[x] Database_Name:".\n );
scanf( "%c", &dname );
printf( "[x] Dumping Database %d", dname );
printf( "waiting...".\n );
system("mysqldump --user=myuser --password=mypass $dname > /var/www/html/uploads/files/$dname.sql");
printf( "[x] Dumped Successfully".\n );
printf( "[x]Do you want to continue ? (y/n) :".\n );
scanf( "%c", &counter );
} while ( $counter != "y" );

getchar();
return 0;
}
thanks...in advance for every answer..
 
Old 04-12-2009, 07:27 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Why write a shell script C ?!?
It will be slower..

As for a mistake in the code, here:
Code:
system("mysqldump --user=myuser --password=mypass $dname > /var/www/html/uploads/files/$dname.sql");
you're trying to use a shell variable ($dname) in C. That won't work.

Last edited by Hko; 04-12-2009 at 07:31 AM.
 
Old 04-12-2009, 07:48 AM   #3
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
You really are making a lot of mistakes in this. I think you should learn a bit of C first. You are mixing up shell script amd C code in a bit of a mess.

You are mixing up characters (bytes) and character strings - you are using your format strings for printf and scanf incorrectly - you are using carriage returns incorrectly - you are using shell variables in C system calls.

To be honest this looks like a conversion from something in another post when you used Bash script. I think you would be better concentrating on the Bash and getting that working.

I don't wish to sound derogatory or be overly critical but the whole thing needs a rewrite - honestly get the Bash version to work - it will be less work.

Last edited by bgeddy; 04-12-2009 at 07:50 AM.
 
  


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 find out if my system is i386, i486, or i586? Is there a system info command? mlsbraves Linux - General 6 02-17-2009 04:08 PM
system command navderm Programming 4 01-02-2009 01:46 AM
list file system linux supports "please give the command or system call" varun_shrivastava Linux - General 4 01-09-2007 07:28 AM
where is command "cd" located? or is it a command/ system call? feetyouwell Linux - Software 5 10-01-2004 08:01 PM
System info command downinthemine Linux - Software 3 11-29-2003 12:30 PM

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

All times are GMT -5. The time now is 03:20 PM.

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