Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OK I tink if code pass all unit tests it's good code. Your code is good, but use std::string not char array with cin >>. If you want to catch all words that have ' , you can use boost regex lib http://www.boost.org/doc/libs/1_35_0/libs/regex/doc/html/index.html

I think you have over complicated things for this assignment. All the op wants is for the program to detect when the word includes the letter 'i'. Doing regular expressions if far far beyond the scope of this assignment.

Alex Edwards commented: Lol that gave me a laugh! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In the sort run yes you are right that it would save time. But it hurts you in the long run -- now that you have found the answer on your own I'll bet you will know where to look next time. And, if you are like me, during your research you read lots of stuff that will be useful to you in the future.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What is c_str() doing?

>What is c_str() doing?
Why don't you read a C++ reference and find out?

Why would I go into a C++ reference and go looking for the command when someone like you could clearly help me quicker

I am very capable of learning on my own. I have books and I study the language. My questions was on a very small piece of code which I assumed wouldn't be nearly as easy to find as a conventional command such as cout.

I won't make the mistake of thinking this forum was for C++ support again...

If you already have a c++ book then why didn't you just look up your question in your book? I'm certain there is a description of std::string class in that book. If there isn't, they you need a different book.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why would I go into a C++ reference and go looking for the command when someone like you could clearly help me quicker

Because, give you bread and you may eat for one day, but teach you how to grow food and you will eat forever. Yes, Narue, or anyone else here, could easily just give you the answer and the next time you have another question you will have no clue how to get the answer so you will be right back here asking again. But if you learn how to look up the answers to your questions you will be able to answer your question yourself, saving you lots of time and effort. Its to your own benefit that you learn how to look up the answers to your questions, and ask us only when you can't find the answers somewhere else.

William Hemsworth commented: nicely said :) +2
Salem commented: Mmmm - fish +18
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look at local area colleges -- there muist be one nearby.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to learn socket programming. See any of these tutorials. And see these FTP links

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

STL does nothing for MS-Windows programming. The intent of STL is portability not anything os-dependent. MFC and STL are not either or situation -- learn both. If I were going to begin a new project today I don't think I would use MFC because there are several other alternatives such as C#, CLR and wxWindows. MFC is a really old class developed by Microsoft as a wrapper for win32 api functions many years before any of those other languages were invented. IMO the only reason to use MFC today is for maintaining old code. If you want to learn MFC, fine, but you should probably concentrate your learning efforts on other previously mentioned languages and wrapper classes.

iamthwee commented: Good advice especially coming from someone who uses MFC +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>No where in the program they have used X.
But it has -- its used in the macro Y

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would write it like this: (this code works only when the power is a positive number)

You are right -- the solution I posted doesn't work for power of 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>3^3 = 27.
that's the wrong answer, so you program will never get it (unless the program is wrong) :)

you over-complicated your program -- the solution is much simpler

int byThePower(int number, int power)
{
    if(power >1)
        number = number * byThePower(number,power-1);
    return number;

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 15: does nothing so you might as well delete it.
The loop lines 14-25 can be rewritten like this:

char word[20];
while(1)
{
   cout << "Enter a word which includes NO i's : ";
   cin >> word;

   if( strchr(word,'i') )
   {
      cout << endl << "I asked for no i's!";
   }
   else
       break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post what you have tried.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It is possible for the ActiveX, to open a choose folder dialog?
I don't see why not, as long as the computer is running MS-Windows

>>How I send the content(files) to the server?
It would seem to be that the transfer process would be greatly improved if you would zip up the folder and all its files then just transfer the zip file. If you don't zip them up then you will have to send each file individually.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is nothing to say sorry about, but if u cud help me out i will really be thankfull to u.

Go back and reread the first two or three posts to this thread -- your question has already been answered. Its up to you to study and test them out ... we can't do that for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't look very hard did you? Click here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is getting people to use code tags, not using the right language. People who don't use code tags will also not use that dropdown.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see a proglem with that code snippet. Key loggers have both legal and illegal uses and the code snippet makes no comment about either. The code snippet used perfectly legal and publically documented functions and there is no intent to being sneeky about it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

link doesn't work

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh gee -- that sure took a loooong time to find. Learn to use google.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You do not need ODBC. Just open the text file with standard fstream object. Text files do not need connection strings like SQL databases such as MySql.

If your looking to learn ODBC, there are tons of c++ classes, some free and some not free. Just google for them and see what you can find. There are also several tutorials that can be found by google.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Will the compiler delete those string literals on heap for us?
Yes, similar that it deletes all the code when the program quits. Depending on the compiler and options you choose string literals may not be on the heap but reside in read-only memory along with executable code. So the only thing you can assume about string literals is that you should not attempt to change or delete them.

string literals can never be deleted -- they remain in memory for the lifetime of the program. This is not counted as or the same as a memory leak.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> delete[] str; //delete the Candy to avoid memory leak

Don't do that because you don't know where str is allocated. The caller may call that function several ways, so its best to leave it up to the caller to delete the string when necessary. Any of the following sanerios are possible, and the CCandyBox constructure has no clue which one was used.

CCandyBox box; // use default constructor, in this case the string will be in the heap so its not necessary to delete it.

CCandyBox box("Candy"); // same as above

char str[] = "Candy";
CCandyBox box(str); str is on the stack but its not a pointer which was allocated by new, so delete will fail.

char* str = new char[10];
strcpy(str,"Candy");
CCandyBox box(str); // str was allocated by new, and must use delete[]
delete[] str;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

actually writer() coulld be simplified like this: (removing one parameter)

void writer (const char* message,  FILE* stream)
{
       fprintf (stream, "%s\n", message);
       fflush (stream);
}

But if the program on the receiving end needs all the arguments including spaces, then you can easily construct a single string to represent that

int main(int argc, char **argv)
{
    int i;
    char buffer[255] = {0};
    for(i = 1; i < argc; i++)
    {
         strcat(buffer, argv[i]);
         strcat(buffer, " ");
    }
    ...
    ...
    writer(buffer, stream);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would think that would be pretty obvious if you wrote all that code yourself. This will send the entire string to writer() -- you should lete writer() worry about how to send the characters through the pipe.

else {
        
        FILE* stream;
       
        close (fds[0]);
       
         
      stream = fdopen (fds[1], "w");
      for(i = 1; i < argc; i++)
     {
        writer (argv[i], 1, stream);}
      }
      close (fds[1]); // not sure about the placement of this line.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>this does not work, what about white spaces

The command interpret ignores all white space (except to separate the actual parameters), so programs don't see them. These are all the same to your program, they both produce the same results.

./a02 23 3
./a02     23          3

>>says the count is one--- needs to be three
The value of argc should be 3 in the example you posted. You probably did not test the program correctly.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

argc contains the number of command-line arguments. in your example it will be 3, the filename + 2 arguments = 3. If you want the number of characters in the arguments just run through argv and count them.

int main(int argc, char* argv[])
{
    int counter = 0;
    int i;
    for(i = 0; i < argc; ++i)
        counter += strlen(argv[0]);
   printf("The number of characters is %d\n", counter);
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not just use fgets() to get the entire line then you can use strtok() or some other method to extract the data. fgets() will automatically go to the next line without you having to do anything extra.

// this will read the entire file.
char buf[255];
while( fgets(buf, sizeof(buf), infp) )
{
    // do something with this line
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can look at the DataReel libraries. It is a set of lots of c++ classes/programs/examples that have been ported to both *nix and MS-Windows, and supports all the popular compilers on both operating systems.

It has support for client/server architecture, but I don't know if that's what you are looking for.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I really doesn't argree with you using the standard libs .

When just starting to learn the c++ language always always use standard c++ set of STL and other header files/streams. They are portable to any modern c++ compiler on any operating system, and there are hundreds of books that teach them too. He's trying to learn c++, not win32 api.

.If you learning C++ ( that means that you don't know the core c++ ) then use the iostream.h include file.

That's like advising a teenager to learn to drive a car by riding horse-and-buggy. iostream.h never was and is not now part of the c++ standards, and went out of style probably over 10 years ago. Your advise is just so much rubbish.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first parameter to fread() must be a pointer. What you are attempting to pass is an integer. Use the pointer & operator and it should fix that. That is inteded to read the binary version of an integer, not the text version. If the file is a text file (that is, a file that is easily readable by Notepad.exe or some other text editor) then you don't want to use fread() at all. Post an example of the file so we can tell you how it should be read.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 33: buffer is a character array, therefore it will never be < 0 and that while loop makes absolutely no sense.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I doubt the singer would make it on American Idol (or whatever its called in UK).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Go back to the Microsoft site where you got that compiler and it will have link(s) to tutorial(s) about how to use the IDE. It takes a little practice, but you should bet the basics right away. Just remember, VC++ 2008 Express is NOT Turbo C++, so don't expect to use it the same way. With VC++ 2008 Express (or any other 32-bit compiler) you don't have to worry about segments, memory models, NEAR or FAR pointers, 640K barrier or any other of those limitations found in Turbo C++. You will also notice from the previously posted code that STL header files do not have .h extension. Those are the new and improved versions that Turbo C++ does not support.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If that is the case then the program uses the current working directory, which is not D:
Am I right ?

You are right -- as I said a couple times before _getcwd() gets the current working directory, which is the drive letter of the CD or DVD drive when run from CD/DVD. And you can see that in the output that I posted --

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

when you said this works, did you compile it and run it as an exe?

does it work then when you have the 2 files on the cd?

any ideas why mine might not im using bloodhsed dev-C++ - is there something else i can try?

When I run the program on the CD I didn't give it any command-line arguments. I just used Windows Explorer and double-clicked on the exe file. The compiler I used is VC++ 2008 Express, but for that tiny program there should be no difference because it doesn't use any compiler-specific stuff, just straight c++ and win32 api functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>{B b; D d; b=d.fd(); cout<<b.i<<endl;}
In program 1 that only works because it isn't using the reference that was returned but its using another copy of that class. Try this and retest: {D d; B& b=d.fd(); cout<<b.i<<endl;}

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This worked perfectly for me:
Output of the program in the command window when run directly from the DVD drive.

start iexplore.exe F:\dvlp\the_index.html

here is the exact code

#include <string>
#include <iostream>
#include <windows.h>
#include <direct.h>
using namespace std;
#pragma warning(disable: 4996)

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     else 
     {
          char path[_MAX_PATH];
          if( getcwd(path, sizeof(path)) == NULL)
         { 
                cout << "Error getting current directory\n";
                return 1;
          }
          command += path;
      } 
 
     command += "\\the_index.html";
     cout << command << "\n";
     system(command.c_str());
     cin.get();
     return 0;
}
Prabakar commented: Thanks, I Learned the fn getcwd() +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually, now that I look at your program closer, your program doesn't write anything to those files. In post #5 above, the program opens the file on line 16 and closes it on line 53, never writes anything to it inbetween those two lines. So, somewhere before line 53 you have to add code to write the data to the file. What to write? Look at line 60 -- you have to write those entries (name, course title, id number, dob, and average) to the file. Then after line 59 you have to insert another line or so that reads those same variables from the file. Use fscanf() or fgets() to do that.

raja289 commented: THANKS ALOT FOR UR USEFUL SUGGESTIONS +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ps this is the link to what i was trying to use...
It appears that the author of that argicle uses %0 to substitute the drive letter found in argv[0], but that may or may not work because the contents of argv[0] is compiler dependent. So it looks like the code I gave you to use getcwd() is a good substitute.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to include <direct.h>

yes, a ) is missing if( getcwd(path, sizeof(path)) == NULL)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if i try that it doesnt load in ie, which is why i was trying to basically autodetect the current directory,

When the program runs from a CD or DVD drive, the current directory is the drive letter of that drive. On my computer it would be either e: or f: (I have both a CD and DVD drives). Is the *.html file also on the CD ? If yes, then your program can call _getcwd() to get the path to the current working directory. Just add that to the code I posted previously

#include <string>
#include <windows.h>

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     else 
     {
          char path[_MAX_PATH];
          if( getcwd(path, sizeof(path) == NULL)
         { 
                cout << "Error getting current directory\n";
                return 1;
          }
          command += path;
      } 
 
     command += "\\the_index.htm"       
     system(command.c_str());
     return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What is %0 supposed to represent? If you put that in a batch file then it is the first command line argument to the batch file, for example c:>mybatch.bat d: <Enter key> If you want to do a similar thing in a C or C++, all command-line arguments are in the argc, and argv parameters to main()

#include <string>

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     command += "\\the_index.htm"       
     system(command.c_str());
     return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb Bones. I remember those days too where I worked in the military. The first computer I ever saw was housed on three floors of a 5-story concrete building (1963). Now it can be fit in the palm of my hand.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I attempt to do that from a command prompt I get that same error because there is no such thing as "%0...". Where did you get the idea of that %0 from anyway?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There's nothing wrong with gambling.

Not if you are a millionaire or better and can afford to constantly lose. The problem is that most gamblers are not wealthy and can't afford to lose. So, yes, there is a lot of things wrong with gambling for those who don't know when to stop.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You're right -- I forgot about the const modifyer satisfying the overload conditions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A c++ compiler will produce errors on that code because in order to overload a function the parameters must be different. In the code you posted both versions of the function have the same identical parameters. So your question is moot because that code can not be compiled.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The second version is actually illegal because the object being returned is created on the stack, and that object is destroyed when the function returns, therefore it will not exist and the returned reference will be invalidated.

The first version (without reference) is ok because the program will actually duplicate the class when it is returned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This might actually result in an infinite loop because it keeps expanding the file as the loop progresses

#include <fstream>
// and other headers

string temp_string;
char result;
long pos;


fstream studfile;
studfile.open("student.dat", ios::in | ios::out); // Is this correct?

while (getline ( studfile, temp_string) ) 
{
     pos = studfile.tellg(); // get current file position     
     studfile.seekg(0, ios::end); // seek to end of file
     studfile << "Results: " << result << endl << flush();
     studfile.seekp(pos, ios::beg); // seek back to previous read position

}