473,748 Members | 7,590 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 1403
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
3140
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
1361
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
1764
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
4996
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
3613
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
1974
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
2934
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
1626
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
3450
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
8991
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
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
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
9249
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
8244
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...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.