Help me!!!
i am making a simple file handlng program in C but was stuck when come to know that i dont know the directory where to store the text file ...that is accessed in the program for R/W mode????????....could someone give the default directory......i m using kali linux
|
Quote:
There IS no 'default directory'...since you wrote this code, you must know what directory you have it set to, since you're handling files. Also, Kali Linux is **NOT** for new users, nor should it be used as a development system. Kali is highly specialized for network security testing, and their website even says so. You are going to be missing quite a lot of development tools and things will only be harder for you. |
Check out this thread for help on kali Linux https://www.linuxquestions.org/quest...ad-4175614092/
|
what TB0ne said, something like
"How to set default directory in C" then explain what you're trying to do. |
The cwd ("current work directory") is inherited from the calling proccess.
It can be obtained by a getcwd() call. It can be changed by a chdir() call. |
what should be the directory where file would be kept("emp.rec").using linux disto(kali linux)
#include <stdio.h>
int main() { FILE *fptr; char name[20]; int age; float salary; /* open for writing */ fptr = fopen("emp.rec", "w"); //what should be the directory where file would be kept if (fptr == NULL) { printf("File does not exists \n"); return; } printf("Enter the name \n"); scanf("%s", name); fprintf(fptr, "Name = %s\n", name); printf("Enter the age\n"); scanf("%d", &age); fprintf(fptr, "Age = %d\n", age); printf("Enter the salary\n"); scanf("%f", &salary); fprintf(fptr, "Salary = %.2f\n", salary); fclose(fptr); return 0; } |
you could make it default whatever you want, or provied a means to let the user pick a directory other then the defualt directory you decided on to use. as far as the specift directory for your app here, whereever you want it to go.
question: is it a user file or system file? if user then I'd put it on the user side. if system then I'd put it in the system side. |
Replace emp.rec with ./emp.rec this will put it in the same folder as the source/app unless you put the app into a bin then it will save to your home folder.
|
All times are GMT -5. The time now is 10:40 PM. |