LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help me!!! (https://www.linuxquestions.org/questions/linux-newbie-8/help-me-4175623186/)

kshitij mishra 02-06-2018 10:30 AM

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

TB0ne 02-06-2018 10:42 AM

Quote:

Originally Posted by kshitij mishra (Post 5816455)
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

If you'd like help, you need to start by reading the LQ Rules, and the "Question Guidelines" and "How to ask a smart question" links in my posting signature. Saying "help me!" doesn't tell anyone about your issues. Also, asking about programming without actually posting the code you've written doesn't give us anything to go on.

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.

Mill J 02-06-2018 11:26 AM

Check out this thread for help on kali Linux https://www.linuxquestions.org/quest...ad-4175614092/

BW-userx 02-06-2018 11:27 AM

what TB0ne said, something like
"How to set default directory in C" then explain what you're trying to do.

MadeInGermany 02-06-2018 11:34 AM

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.

kshitij mishra 02-19-2018 08:39 AM

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;

}

BW-userx 02-19-2018 08:47 AM

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.

Mill J 02-19-2018 08:55 AM

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.