Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Copy, Delete, Rename, Show Unix Files using C

Posted on 2003-03-31
5
Medium Priority
?
173 Views
Last Modified: 2010-04-15
I am trying to write a simple file management prog using a simple menu, can anyone help me start. Thanks in advance.  
0
Comment
Question by:forestfire
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 152 total points
ID: 8238012
Use a loop to display a menu as:

1. Copy
2. Delete
3. Rename
4. Show
5. Exit

and read the choice as an integer (or character). Based on this value, enter a switch statement block and perform the required operations in the corresponding case statement. Also provide for a default statement (invalid choice).

Like:

case 1: Read source filename, destination filename, and then copy (also check if the source-file exists, and whether a file by the destination filename is not already in existence - if so, then ask for another filename).

case 2: Read the filename and check if it is present. If yes, the delete it.

case 3: Read the filename and the new filename. Check if the file exists or not, and that a file by the new filename doesn't already exist. If allowed, then rename the file.

case 4: Read the filename. If the file is present, then read it (line by line, if its a text-file), and display it.

Now, if the choice was not 5 (exit), then loop again, else exit the program.

Hope that helps!

Mayank.

PS: Please don't ask for codes. Try to work out something and if you get any errors, then post it here so that we ca help you out.
0
 
LVL 5

Assisted Solution

by:Kocil
Kocil earned 148 total points
ID: 8239272
And for the functions you need for deleting, renaming, copying etc, pleas look at :
http://www.cplusplus.com/ref/

Search for rename/remove.
There is no ready made copy function. You need to to open the original file for reading, and create the new_file for writing, then read/write manually. Use these functions: fopen, fread, fwrite, fclose, feof;

Show is practically the same as copy, just copy it to stdout instead to a new file.


0
 
LVL 20

Expert Comment

by:jmcg
ID: 10199327
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between mayankeagle and Kocil.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10206761
Please proceed with that recommendation.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question