473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

file I/O, user managed file name C

9
Hi, I am working on a program that read's in a file
and i want the user to manage what file to read in(the file name), and what file to write to.
can someone help me with that ?

thanks //Primus
Sep 4 '07 #1
5 1805
dmjpro
2,476 2GB
Hi, I am working on a program that read's in a file
and i want the user to manage what file to read in(the file name), and what file to write to.
can someone help me with that ?

thanks //Primus
You will let the user to set the Input and Output File name?
Or something else you want?

Kind regards,
Dmjpro.
Sep 4 '07 #2
sicarie
4,677 Expert Mod 4TB
Hi, I am working on a program that read's in a file
and i want the user to manage what file to read in(the file name), and what file to write to.
can someone help me with that ?

thanks //Primus
Sure, what do you have so far or where are you getting stuck?
Sep 4 '07 #3
primpa
9
yes exactly, user will be asked to enter file name to read from, or to write to.
so that u can save things in one file then load from another file.

so far i know how to read and write from/to a file that is in the "code",
i specify file name before i compile in the program source code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. FILE *writefile;
  3. writefile = fopen("movielist.txt","wt"); 
  4.  
  5.     while (list[i].occupied == 1)
  6.     {
  7.         fprintf(writefile, "%s",list[i].name);
  8.         fprintf(writefile, "%s",list[i].genre);
  9.         fprintf(writefile, "%d\n",list[i].year);
  10.         fprintf(writefile, "%d\n",list[i].grade);
  11.         i++;
  12.     }
  13.  
  14.     fclose(writefile);
  15.  
  16.  
do not worry about list[i].occupied, this piece of code does work, if the file
movielist.txt exist in the same directory.

i had an idea to do it like this: writefile = fopen("%s(myfilename)","w");
did not work so well

thanks // Primus
Sep 4 '07 #4
sicarie
4,677 Expert Mod 4TB
yes exactly, user will be asked to enter file name to read from, or to write to.
so that u can save things in one file then load from another file.

so far i know how to read and write from/to a file that is in the "code",
i specify file name before i compile in the program source code.

do not worry about list[i].occupied, this piece of code does work, if the file
movielist.txt exist in the same directory.

i had an idea to do it like this: writefile = fopen("%s(myfilename)","w");
did not work so well

thanks // Primus
I'm sorry, I'm not sure what you are asking, are you trying to append the path to the file name? As you said, your code works, what is your question?
Sep 4 '07 #5
primpa
9
You will let the user to set the Input and Output File name?
Or something else you want?

Kind regards,
Dmjpro.

this is what i want, i think i said that in the first post, and my second post was a
complement to that one. Any how, i try to express my self better now, my question being:

How do i let the user chose the file name, user being he person who runs the
program.
I have some data in the program and i want to output it to a file that don't exist.
And so let the user make the file name, path is not important. And the same thing to input data from a file to the program.
The user should specify file name when deeling with file operations

I really hope this is clear ?

thanks / Primpa
Sep 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joca | last post by:
Hi. I have a problem with a dirname. I can´t read a file if i write this code: <?php $user = $_REQUEST; $filename = dirname(_FILE_).'/../revadv/$user'; $lines = file($filename); ?>
1
by: Scott Chang | last post by:
Hi all, I loaded the following program 'HelloMCPP' to my MS VC++ .NET (2002) that is installed on my Windows XP Professional PC: ------------------------------------- AssemblyInfo.cpp...
4
by: Richard | last post by:
Hi all, Is there any class in .NET 1.x that will help me set file & folder permissions for a user? Aka - I would like to do the in code equivalent of right clicking a folder in file explorer...
17
by: spentun | last post by:
How can I moitor file which is executed by user or program in window. I need to write a code to monitor file. When user clicks the file(.exe) or is called by program, the name of file will be...
1
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
5
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the...
2
by: Visine_Eyes | last post by:
What .NET mechanism should I use to resolve permission issues before I begin to copy directory structure/file(s) from one computer to another. I have tried Try/Catch statement using DirectoryInfo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.