Im trying to use the system() function to access and use the cmd. The problem though is that im trying to change directories,but its not allowing me. Im typing
- Code: Select all
system("cd C:\\)
system("cd C:\\)

Acidiferous wrote:A little background on what you are trying to do would help, or maybe it's just me who is slow<br><br>Anyway, if you are planning on making 2 commands in a row, where one should start where the last one stopped, it's not going to work like that.<br>I dont know if it's the forum and the pasting that ate a little of your code, but i spottet a minor error, you are missing a "<br><br>Descripe what you are trying to do and i will be happy to help you, if i can
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
system ("cd C:\\");
return 0;
}

xTractatorix wrote:Yeah sorry about the vaugness of my post i was in a hurry. Okay what im trying to do is use the system() function to automate commands in my C program. What im having a problem with is not build errors its that when i try to change directorys usind the cd command its gives me the message in the command line "Volume C has no label". I dont know what im doing wrong.. heres my sorce code.
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
system ("cd C:\\");
return 0;
}




#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (system("cd c:\\ && dir") != 0) {
perror("system");
return 1;
}
return 0;
}#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (chdir("..") != 0) {
perror("chdir");
return 1;
}
if (system("dir") != 0) {
perror("system");
return 1;
}
return 0;
}

pertti123 wrote:
- Code: Select all
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (chdir("..") != 0) {
perror("chdir");
return 1;
}
return 0;
}

Users browsing this forum: No registered users and 0 guests