All that is necessary for evil to succeed is that good people do nothing! Support Act for America

how do i execute a command in C code? - Page 2 - Anarchist Cookbook
Anarchist Cookbook  

Go Back   Anarchist Cookbook > Anarchist Cookbook > Hacking > Programming

Programming Got code?

Reply
 
Thread Tools Search this Thread Display Modes
Old January 12th, 2009   #11
ishkur88
Senior Member
Points: 5,313, Level: 31
Points: 5,313, Level: 31 Points: 5,313, Level: 31 Points: 5,313, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
ishkur88's Avatar
 

Last Online: 1 Day Ago 06:01 PM
Join Date: Nov 2006
Location: the internet.
Age: 25
Posts: 1,104
Cash Credits: 6,001
ishkur88 RSS Feed
Send a message via AIM to ishkur88 Send a message via MSN to ishkur88 Send a message via Yahoo to ishkur88
Quote:
i know i could use a batch file, thats what i did anyways, but i wanted to take it a step further and do it in c, and i searched google but didn't find much
Doing it in Batch and doing it in C are almost complete polar opposite sides of the spectrum when you're talking about doing something like that.

Automating series of commands into a script (which is what you want to do) is in the realm of Batch. Doing that in C would require you to know a lot more, and doesn't really make sense.

Just KISS and use a Batch job to do your bidding.

*note to other users: This is one of the rare exceptions that I will endorse the use of a Batch file. He is simply wanting to make a trivial set of tasks easier... rather than trying to do childish bullshit to 'hack' the command prompt*
__________________
I am not young enough to know everything.
ishkur88 is offline   Reply With Quote
Old January 12th, 2009   #12
twenglish1
Senior Member
Points: 5,393, Level: 31
Points: 5,393, Level: 31 Points: 5,393, Level: 31 Points: 5,393, Level: 31
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
twenglish1's Avatar
 
Kill Tweety Champion!
Last Online: 2 Hours Ago 11:55 PM
Join Date: Aug 2008
Location: Pittsburgh, PA
Age: 15
Posts: 2,001
Cash Credits: 24,133
twenglish1 RSS Feed
ok, i wrote this code over with the system line in but it still won't work.
code:

#include "stdio.h"
char drive;
char x;
int main(void){
printf("Enter Drive letter:\n");
scanf("%c", &drive);
printf("Drive %c will now be formatted!\n", drive);
system("format &drive");
return 0;
}

it compiled but when i enter the drive letter nothing happens and it keeps repeating, its probably a really simple problem, but please give me a break, i'm fairly new to c programming
twenglish1 is offline   Reply With Quote
Old January 12th, 2009   #13
ishkur88
Senior Member
Points: 5,313, Level: 31
Points: 5,313, Level: 31 Points: 5,313, Level: 31 Points: 5,313, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
ishkur88's Avatar
 

Last Online: 1 Day Ago 06:01 PM
Join Date: Nov 2006
Location: the internet.
Age: 25
Posts: 1,104
Cash Credits: 6,001
ishkur88 RSS Feed
Send a message via AIM to ishkur88 Send a message via MSN to ishkur88 Send a message via Yahoo to ishkur88
Just at a glance, Its probably the drive letter itself that's the problem.

I think the syntax for the 'format' command is as follows:

Quote:
format C:\
If I'm not mistaken.

In your program, you're storing the drive letter in a single char, instead of a char array or a string. This means that 'format' will, at best, get "C" as its argument (instead of "C:\")... which it may or may not be able to accept.

Take a look at this for some help with character arrays (strings) and how to reading user input.

And... again, I don't think a call to system is the best way to accomplish this task. All you're making is a overzealous batch file. Do you want to format the partition, or delete all files?

If you just want to delete the files, you can take a look at what they've done here:

__________________
I am not young enough to know everything.
ishkur88 is offline   Reply With Quote
Old January 13th, 2009   #14
twenglish1
Senior Member
Points: 5,393, Level: 31
Points: 5,393, Level: 31 Points: 5,393, Level: 31 Points: 5,393, Level: 31
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
twenglish1's Avatar
 
Kill Tweety Champion!
Last Online: 2 Hours Ago 11:55 PM
Join Date: Aug 2008
Location: Pittsburgh, PA
Age: 15
Posts: 2,001
Cash Credits: 24,133
twenglish1 RSS Feed
yah i know that is the syntax but my problem is getting the char with the drive letter into the command
twenglish1 is offline   Reply With Quote
Old 1 Week Ago   #15
Truant
Member
Points: 103, Level: 2
Points: 103, Level: 2 Points: 103, Level: 2 Points: 103, Level: 2
Activity: 18%
Activity: 18% Activity: 18% Activity: 18%
 

Last Online: 1 Day Ago 08:21 AM
Join Date: Jun 2009
Location: Now it's your business, 'eh?
Posts: 39
Cash Credits: 639
Truant RSS Feed
Quote:
Originally Posted by twenglish1 View Post
i am new to C programming but i am learning. i am trying to make a program that will format a drive but i don't know what code i would use to execute the format command.

here is the code:

#include "stdio.h"

int main(void){
char drive;
char x;
printf("Enter Drive letter:\n");
scanf("%c", &drive);
printf("Drive %c will now be formatted!\n", drive);
(format command goes here)
return 0;
}

what do i use to format the drive please help!!!
Here is the idea: do what you did, strncat the drive letter, the command, and the semicolon, and then call system() and pass the array.

#include "stdio.h"

int main(void){
char drive;
char x;
char cmd [ 20 ];
printf("Enter Drive letter:\n");
scanf("%c", &drive);
printf("Drive %c will now be formatted!\n", drive);
cmd = strncat ( "format ", drive );
cmd = strncat ( cmd, ":" );
system ( cmd );
return 0;
}


This code will only work for Windows, and I am not sure that you use strncat. It maybe different.
Truant is offline   Reply With Quote
Old 1 Week Ago   #16
DoG MikkyW
Member
Points: 3,461, Level: 24
Points: 3,461, Level: 24 Points: 3,461, Level: 24 Points: 3,461, Level: 24
Activity: 51%
Activity: 51% Activity: 51% Activity: 51%
 
DoG MikkyW's Avatar
 

Last Online: 8 Hours Ago 05:44 PM
Join Date: Mar 2008
Location: Florida
Age: 21
Posts: 995
Cash Credits: 13,648
DoG MikkyW RSS Feed
Send a message via ICQ to DoG MikkyW Send a message via AIM to DoG MikkyW Send a message via MSN to DoG MikkyW Send a message via Yahoo to DoG MikkyW
Sweet!!! This is the first necro-post that can't be counted as a necro-post because it actually adds something important to the main subject. Kudos.
DoG MikkyW is offline   Reply With Quote
Old 1 Week Ago   #17
putkapopper1990
Junior Member
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 

Last Online: 1 Week Ago 02:40 PM
Join Date: Jun 2009
Posts: 6
Cash Credits: 309
putkapopper1990 RSS Feed
not quite sure but my friend can do all this real good,.
putkapopper1990 is offline   Reply With Quote
Old 3 Days Ago   #18
Truant
Member
Points: 103, Level: 2
Points: 103, Level: 2 Points: 103, Level: 2 Points: 103, Level: 2
Activity: 18%
Activity: 18% Activity: 18% Activity: 18%
 

Last Online: 1 Day Ago 08:21 AM
Join Date: Jun 2009
Location: Now it's your business, 'eh?
Posts: 39
Cash Credits: 639
Truant RSS Feed
So ask him, and have something to add to the conversation before posting! Spam posts aren't good.
Truant is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:19 AM.


Powered by Anarchy and vBulletin® Version 3.7.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios