whenever, i try to open a file for writing using fopen("xyz.txt" , "w"), i am able to create the file only in default C:\ drive. i want to create a directory in the process of running the c code and want to create the file in that directory.
So, i would like to know:
1.) How to create a directory in c ? (in linux and windows)
2.) How to create a file in the directory which has been created ? (in linux and windows)
I tried but i failed.
Here is what i tried (on linux platform):
#include <stdio.h>
#include <sys/stat.h>
int main(){
FILE *fp;
mkdir("c:\temp" );
fp=fopen("c:\te mp\sample.txt", "w+");
fprintf(fp, "Hello World !!");
return 0;
}
So, i would like to know:
1.) How to create a directory in c ? (in linux and windows)
2.) How to create a file in the directory which has been created ? (in linux and windows)
I tried but i failed.
Here is what i tried (on linux platform):
#include <stdio.h>
#include <sys/stat.h>
int main(){
FILE *fp;
mkdir("c:\temp" );
fp=fopen("c:\te mp\sample.txt", "w+");
fprintf(fp, "Hello World !!");
return 0;
}
Comment