Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-15-2004, 01:30 PM   #16 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-15-2004, 03:00 PM   #17 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
add this below the headerfiles:
using namespace std;
__________________
Valmont is offline   Reply With Quote
Old 12-16-2004, 11:11 AM   #18 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-16-2004, 01:12 PM   #19 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
No it doesn't do that. You will need learn a framwork for that like Win32 programming, MFC, wxWidgets, or Qt.
__________________
Valmont is offline   Reply With Quote
Old 12-16-2004, 05:33 PM   #20 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-17-2004, 02:05 AM   #21 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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
__________________
Valmont is offline   Reply With Quote
Old 12-17-2004, 04:22 AM   #22 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 12-20-2004 at 12:35 PM.
redhead is offline   Reply With Quote
Old 12-17-2004, 06:46 PM   #23 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
ok, just one more question, how do i select a destination of the folder i want it to search?
Androto is offline   Reply With Quote
Old 12-19-2004, 07:29 AM   #24 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-20-2004, 09:45 AM   #25 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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?
Androto is offline   Reply With Quote
Old 12-20-2004, 12:30 PM   #26 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-20-2004, 04:09 PM   #27 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-20-2004, 04:17 PM   #28 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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
Androto is offline   Reply With Quote
Old 12-21-2004, 08:04 AM   #29 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-21-2004, 05:26 PM   #30 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
ok, i'll try to figure out the rest on my own. thanks for the help.
Androto is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading files from a directory and printing philthee Java 4 10-29-2004 05:01 AM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM
Linking files? ShadowSoft Standard C, C++ 3 02-27-2003 12:33 PM
All Class Files mixingsoup PHP 12 12-04-2002 06:49 AM


All times are GMT -8. The time now is 11:52 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting