LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2018, 10:30 AM   #1
kshitij mishra
LQ Newbie
 
Registered: Feb 2018
Posts: 2

Rep: Reputation: Disabled
Question 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
 
Old 02-06-2018, 10:42 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by kshitij mishra View Post
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.
 
1 members found this post helpful.
Old 02-06-2018, 11:26 AM   #3
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Check out this thread for help on kali Linux https://www.linuxquestions.org/quest...ad-4175614092/
 
1 members found this post helpful.
Old 02-06-2018, 11:27 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
what TB0ne said, something like
"How to set default directory in C" then explain what you're trying to do.
 
Old 02-06-2018, 11:34 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,792

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.

Last edited by MadeInGermany; 02-06-2018 at 11:42 AM.
 
Old 02-19-2018, 08:39 AM   #6
kshitij mishra
LQ Newbie
 
Registered: Feb 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
Unhappy 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;

}
 
Old 02-19-2018, 08:47 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
 
Old 02-19-2018, 08:55 AM   #8
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
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.
 
  


Reply



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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration