LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 11: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, 11:42 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,236

Rep: Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973Reputation: 5973
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, 12:26 PM   #3
Mill J
Member
 
Registered: Feb 2017
Location: 127.0.0.1 Sweet 127.0.0.1
Distribution: Void, MX, Haiku, Icaros, Puppy and many others
Posts: 977
Blog Entries: 2

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
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, 12:27 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ Win10
Posts: 9,516

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

Rep: Reputation: 582Reputation: 582Reputation: 582Reputation: 582Reputation: 582Reputation: 582
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 12:42 PM.
 
Old 02-19-2018, 09: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, 09:47 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ Win10
Posts: 9,516

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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, 09:55 AM   #8
Mill J
Member
 
Registered: Feb 2017
Location: 127.0.0.1 Sweet 127.0.0.1
Distribution: Void, MX, Haiku, Icaros, Puppy and many others
Posts: 977
Blog Entries: 2

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration