473,699 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processing pathnames listed in a text file.

I want to open a file with a known location and process its contents. The
contents are to be treated as a list of pathnames. Each pathname is an
absolute or relative pathname in the following sense:

- the current directory is the directory of the opened file
- the root directory is the program directory (i.e., working directory of
the program under execution)

A pathname is processed by opening a file and displaying its contents. The
location of this file is specified by the pathname in either absolute or
relative form.

I worked with a friend to come up with the main function:

#include <iostream>
#include <string>

void process_file(st d::string name);

int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
return 1;
}
process_file(st d::string(argv[1]));
return 0;
}

We don't know where to go from here. Any advice or code is appreciated.
Jul 23 '05 #1
3 1400
Jason Heyes wrote:

#include <iostream>
#include <string>

void process_file(st d::string name);

int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
return 1;
}
process_file(st d::string(argv[1]));
return 0;
}

We don't know where to go from here. Any advice or code is appreciated.


Look up the file stream classes ifstream and ofstream.

Seriously. If this is all you two have nailed down by now, then you should try
your hands on something simpler.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #2
> I want to open a file with a known location and process its contents.
The
contents are to be treated as a list of pathnames. Each pathname is an absolute or relative pathname in the following sense:

- the current directory is the directory of the opened file
- the root directory is the program directory (i.e., working directory of the program under execution)

A pathname is processed by opening a file and displaying its contents. The location of this file is specified by the pathname in either absolute or relative form.

I worked with a friend to come up with the main function:

#include <iostream>
#include <string>

void process_file(st d::string name);

int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl; return 1;
}
process_file(st d::string(argv[1]));
return 0;
}
We don't know where to go from here. Any advice or code is

appreciated.

You need to implement the process_file() function. (which IMHO should
take a std::string const & as a parameter instead). Is this your
homework assignment? It doesn't make since to me that somebody could
write the above main and not know what to do next.

Jul 23 '05 #3
Jason Heyes wrote:

Ok we tried again and got a partial implementation of process_file.

void process_pathnam e(std::string pathname, std::string name);

void process_file(st d::string name)
{
std::ifstream in(name);
if (!in.is_open())
return;

std::string pathname;
while (in >> pathname)
process_pathnam e(pathname, name);
}

Can you help us figure out how to process the pathname itself?
What do you need to do with it
You said for youself:
Each pathname is an absolute or relative pathname in the following sense:

- the current directory is the directory of the opened file
- the root directory is the program directory (i.e., working directory of
the program under execution)


So it seems to me you need to do some string manipulations and checkings
to figure out:

is this an absolute path name or a relative one?

If it is an absolute one, what else needs to be done?
(Append it to the program directory. You may check if
your system passes that information as argv[0] to main())

If it is a relative one, what else needs to be done?
(Append it to the directory of the opened file. That
one might get a little bit tricky to get on.)

In any case you finally come up with a pathname that is
valid for the operating systems file structure. Open
the file and dump its content.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3137
by: Danny Anderson | last post by:
Hola, PHP folk! I have a php page that contains a self-processing form. The form holds search results. The search terms originally came from the previous page, but the user can repeatedly refine the results on the page in question until the target item can be found. This search refinement is where the self-processing form comes to play. The search results are listed in a table with a radio button at the end of each row. What I...
1
1357
by: draco | last post by:
Hi, Let's say I have a dynamic library libapple.so with a method applemethod() which expects a filename string. I call this method from main() which is in the file foo.c. Now foo.c and apple.so are in different directories, and the user calls foo.c with a relative pathname to the file. My question is how do I make sure that applemethod knows where this file is from the realtive pathname? foo.c:
11
1760
by: Glen Wolinsky | last post by:
This is my first attempt as asynchronous processing. I have created a small test app as proof of concept, but I am having one proglem. In the example (code listed below), my callback routine has two problems: 1. It runs TWICE; and 2. While it seems to update the web page controls, the results never show up on the page. I am using delegates per a couple of examples I found on MSDN and elsewhere.
6
4991
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
4
3605
by: Alexis Gallagher | last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if this is a double-post.) Is it possible to do very fast string processing in python? My bioinformatics application needs to scan very large ASCII files (80GB+), compare adjacent lines, and conditionally do some further processing. I believe the disk i/o is the main bottleneck so for now that's what I'm optimizing. What I have now is roughly as follows (on python...
15
1968
by: Jack | last post by:
Hi, I have a asp form where one element is a list box which lists four years starting from 2004. This list is drawn from a database table which has YearID and Year as two fields as shown below: YearID YEAR 1 2004 2 2005 3 2006 4 2007 PART OF ASP CODE IS:
22
2930
by: Sven-Thorsten Fahrbach | last post by:
Hi Does anybody know of a library that offers a function to split pathnames. It should work somewhat like the following code snippet: ----------------- char *path = "/home/user/Documents/Textdocuments/Bills"; char **dirs; splitPath(path, dirs);
2
1622
by: garyusenet | last post by:
Hi All, I have been working on the following programme over the last day or so and have made a good deal of progress. It is a very simple programme, but is proving very useful as a learning aid, and will eventually be useful to me in it's own right. It function is to open a text file, and remove HTTP addresses from the file. The file is always in a certain format, and the HTTP address is always proceeded by a key phrase.
1
3443
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know elisp, first take a gander at Emacs Lisp Basics. HTML version with links and colors is at: http://xahlee.org/emacs/elisp_text_processing.html
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7755
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.