|
 |
|
 |
12-15-2004, 01:30 PM
|
#16 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
line 6: parse error before `(' token
line 6: 'ofstream' undeclared (first use of this function)
line 8: 'CreateOpenTest' undeclared (first use of this function)
line 11: parse error before `(' token
line 11: 'ifstream' undeclared (first use of this function)
line 12: 'ReadOpenTest' undeclared (first use of this function)
line 15: 'endl' undeclared (first use of this function)
line 15: 'cout' undeclared (first use of this function)
this is from the code that i copy and pasted from what you typed earlier.
|
|
|
12-15-2004, 03:00 PM
|
#17 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
add this below the headerfiles:
using namespace std;
__________________
|
|
|
12-16-2004, 11:11 AM
|
#18 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
ok, now that i got it to run, it doesn't do anything. all it does is show the number 5 and end. I thought it would copy all the files with .state at the end and copy it to another folder.
|
|
|
12-16-2004, 01:12 PM
|
#19 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
No it doesn't do that. You will need learn a framwork for that like Win32 programming, MFC, wxWidgets, or Qt.
__________________
|
|
|
12-16-2004, 05:33 PM
|
#20 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Quote:
|
Originally Posted by Valmont
No it doesn't do that. You will need learn a framwork for that like Win32 programming, MFC, wxWidgets, or Qt.
|
why would i have to learn win32 for that, i'm running mac os x. anyways, can't you just give me the code, and maybe i could learn how to program even better by examining the code.
|
|
|
12-17-2004, 02:05 AM
|
#21 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
No I simply can't.
First of all I don't know the mac os-x api. Secondly I don't support api's at all. On this forum I concentrate on conceptualisation, analisys, design and iso C++ only.
Struggle your way through this:
http://developer.apple.com/
Perhaps you might want to find an environment so you can communicate wtih equal minded people 
__________________
|
|
|
12-17-2004, 04:22 AM
|
#22 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,721
|
First of all, I didn't wanted to get into this, since it is OS specific..
I started out by telling you which functions to look up and read on, since they are implemented differently on every OS.
Anyway I've found a solution which is quite ANSI C complient..
Code:
#include <stdio.h>
#include <dirent.h>
#include <string.h>
int found_state(char* name, char* state, int offset);
int main(int argc, char* argv[])
{
DIR* dir_pointer;
struct dirent* directory;
int len, found = 0;
if(argc < 2)
{
printf("Usage: %s <state> [dir]\n\n", argv[0]);
printf("\tIn order to search for every instace of .doc files\n");
printf("\tin the current directory use:\n");
printf("\t\t%s .doc\n", argv[0]);
printf("\tIf it should be searched for in your /usr/lib dir use:\n");
printf("\t\t%s .doc /usr/lib\n", argv[0]);
return -1;
}
len = strlen(argv[1]);
if(argc == 2)
dir_pointer = opendir(".");
else
dir_pointer = opendir(argv[2]);
if(!dir_pointer)
{
printf("Error reading from directory\n");
return -1;
}
printf("Found files:\n");
for (directory = readdir(dir_pointer);
directory != NULL;
directory = readdir(dir_pointer))
{
if(found_state(directory->d_name,
argv[1],
strlen(directory->d_name) - len))
{
found = 1;
printf("%s\n", directory->d_name);
}
}
if(!found)
printf("No files found to match %s\n", argv[1]);
closedir(dir_pointer);
return 0;
}
int found_state(char* name, char* state, int offset)
{
int count;
if(offset < 1)
return 0;
for(count = 0;
name[offset + count] != '\0'
&& state[count] != '\0'
&& name[offset + count] == state[count]; count++)
/* just compare */;
if(name[offset + count] == '\0' && state[count] == '\0')
return 1;
return 0;
}
Now the found_state() function can be altered, infact the entire program can be altered..
But this is the basic directory/algorithem for achieving such things.
Last edited by redhead; 12-20-2004 at 12:35 PM.
|
|
|
12-17-2004, 06:46 PM
|
#23 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
ok, just one more question, how do i select a destination of the folder i want it to search?
|
|
|
12-19-2004, 07:29 AM
|
#24 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,721
|
Try executing the program without giving any arguments to it..
It'll tell you that the second argument is the folder to search ie:
Code:
~> ./program <.state_to_search> [folder_apart_from'.'to_search_in]
It will as default search in current directory, if you give a second argument it will assume that is the folder to search in.
|
|
|
12-20-2004, 09:45 AM
|
#25 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Quote:
|
Originally Posted by redhead
Try executing the program without giving any arguments to it..
It'll tell you that the second argument is the folder to search ie:
Code:
~> ./program <.state_to_search> [folder_apart_from'.'to_search_in]
It will as default search in current directory, if you give a second argument it will assume that is the folder to search in.
|
i'm sorry, but i didn't understand that. what do you mean by running the program without giving any arguments to it?
|
|
|
12-20-2004, 12:30 PM
|
#26 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,721
|
If you compile the program you'd get an executable.
when executing this in a terminal/command prompt, you can chose to just type in the executables name or the executables name followed by something else.
If you just type in the executable the program should return with a warning that it isn't properly used, and should be given an argument telling it what .state in the filenames to look for.
this argument is the thing you can chose to write after the executables name uppon executing it.
In windows you could start a command prompt and type in notepad, this will open up notepad for you, if you have a file called my_file.txt you can type notepad my_file.txt and notepad will open, showing the contence of my_file.txt.
The name my_file.txt is called the first agument given to notepad uppon execution.
In this case with my code, it expects to be given this first argument.
This argument should be the .state to look for, if you don't want to look for it in the current directory (the directory in which you are located when you type in the executable name in order to execute it) then give this as a second argument ie:
Quote:
/my/dir > my_executable .state
will make it search in /my/dir, showing any files which ends in .state
/my/dir > my_executable .state /some/other/dir
will make it search in /some/other/dir, showing any files which ends in .state
|
Does this make it any more clear ??
The way I write it with <> and [] surrounding it, is the way man pages under linux explains it, given that anything within <> is required, and anything within [] is optional.
|
|
|
12-20-2004, 04:09 PM
|
#27 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Quote:
|
Originally Posted by redhead
Does this make it any more clear ??
|
yes, alot more clear. thank you, i'm going to try it out now.
|
|
|
12-20-2004, 04:17 PM
|
#28 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
everytime i try to do this, it gives me the error
Code:
Error reading from directory
i was trying to see all of the .txt files on my desktop and that's what it returned. this is the code i entered into terminal.
Code:
./searcher .txt /users/me/desktop
|
|
|
12-21-2004, 08:04 AM
|
#29 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,721
|
Code:
if(!dir_pointer)
{
printf("Error reading from directory\n");
return -1;
}
Which means it has trouble opening the directory you want it to search in.
This can happen due to many things, one is that the opendir() function is slightly different on your system than on mine, another thing could be theres a typo in the directory argument, yet another one could be that my program fails, when it has to open a directory starting with '/' as well as a noumerous others..
But on my system it has no problem at all:
Quote:
{105} ~> ls /usr/lib/*.15
/usr/lib/liblber.so.2.0.15
/usr/lib/libldap.so.2.0.15
/usr/lib/libldap_r.so.2.0.15
{106} ~> ./di .15 /usr/lib
Found files:
liblber.so.2.0.15
libldap.so.2.0.15
libldap_r.so.2.0.15
|
So from my point of view it is working as expected.
This is one of the reasons I didn't wanted to get into this in teh first place, since it is so system specific, when dealing with something like file/directory structures.
|
|
|
12-21-2004, 05:26 PM
|
#30 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
ok, i'll try to figure out the rest on my own. thanks for the help.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 02:25 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|