WolfPack 491 Posting Virtuoso Team Colleague

C/C++ has been around much longer than VB.

Yep. What would be the word then... deprecated? But I think you know what I mean. I am talking about VB6, and it has not been supported by Visual Studio since this .NET thing.

WolfPack 491 Posting Virtuoso Team Colleague

but i never found it a gud idea.

int i[100] = {0} ;

Why not?

WolfPack 491 Posting Virtuoso Team Colleague

Thanks again. Very much.

btw, have u tried compiling it?
I'm very proud of my primitive program ;)

Well I compiled it, and ran it. Hate to say it but it sucks. There are too many user options to set, and too many controls to memorize. For example I saw the keys to move items only at the start. After the game starts I do not see it. Having a very short term memory, I could only remember that pressing w moves the item above the space down. So naturally I closed the game at that point.

But overall I think the effort is good. And I think you should be proud about your program too. Brush up the rusty patches, mentioned in my above posts. Concentrate on how to make the instructions more userfriendly. Don't go into GUI programming in C/C++ yet. Learn the language first. Otherwise you will fall in a lot of trouble.

WolfPack 491 Posting Virtuoso Team Colleague

newline is not a function. It is a string object. What std::string newline( 50, '\n' ) does is, create a string called newline that has 50, '\n' characters. Since you have used using namespace std; at the beginning, you can just use string newline(50, '\n' ); . You will have to use the #include <string> at the beginning. Then cout just outputs it. I suggest you get a good C++ book if you dont have one, and start reading about C++ strings to learn more. you may fine good tutorials in the internet too.

WolfPack 491 Posting Virtuoso Team Colleague

Skimmed through your program, and it is not cout that seems to be the problem. You are calling cout too much. Remember that optimization of code should start first with your algorithm. The rest will usually be taken care by a decent compiler. Take for example the for loops where you are outputting 50 newline characters.

for ( i = 0 ; i < 50; i++ )
   cout << '\n';

This piece of code calls cout 50 times. IO functions take a lot of time. That means you are writting to the console 50 times which takes a lot of time, when you consider the total number of times you do this in your program.
A better way will be to first create the string with 50 newline characters and output them all in a single cout call. like this

std::string newline( 50, '\n');
    std::cout << newline ;

Clean up your code like that, and you will get to know more modifications where you can make the code fast.

WolfPack 491 Posting Virtuoso Team Colleague

No need to email. You can attach your program here. Make sure you attach code, and not the executable.

WolfPack 491 Posting Virtuoso Team Colleague

C++

I later saw the why? part.
VB, C and C++ are the only ones I know even a little bit. VB is a bit old. No galmour in saying that. C++ supports C too. So I am getting 2 out of 3 when I say C++.

WolfPack 491 Posting Virtuoso Team Colleague

Java or C?

C and Python

The question is what is the programming language, not what are the coolest languages. Decide which one.

WolfPack 491 Posting Virtuoso Team Colleague

Can you explain a bit more on what you are trying to do? Better if you can post the code. Otherwise there will be a lot of answers based on a lot of assumptions.

WolfPack 491 Posting Virtuoso Team Colleague

C++

WolfPack 491 Posting Virtuoso Team Colleague

You would like to try TextPad, Notepad++, or Crimson Editor which are free editors for windows and have syntax highlighting and other features that notepad does not provide.

WolfPack 491 Posting Virtuoso Team Colleague

I don't recall using any tabs,

I should have been more clearer. I was referring to the use of tabs to indent the program. If you just use the tab character as it is, when you copy and paste to daniweb, or view it in another text editor other than the one you typed it, say edit it in Visual Studio Editor and view it in emacs, it may look like this. As you can see, the indenting have all gone askew. If the programmer had used the "replace tabs with spaces" option that comes in most decent editors, you will not see this problem whether you later open it in emacs, vim or visual studio.

WolfPack 491 Posting Virtuoso Team Colleague

It should be #include <cmath>

and remember to use CODE tags the next time.

WolfPack 491 Posting Virtuoso Team Colleague

Since this is a trivial program, there is not much to do to make the program efficient. You could initialize the variables as they are declared, as you said, and yes it is possible to do that with multiple variables too. However, although this may vary on who you work for, the use of declaring multiple variables in the same line is discouraged. One variable in one line will be the rule. You could merge the cout statement without changing your rule for length too.

Another golden rule will be to use the comments before the actual code.
And keep the length of a line under 80 characters. Then you can read the code without horizontal scrolling. This is rather historical when considering the width of the screen has increased since the 680 x 480 type, but this would come in handy if you review printed code.
I have often tried to get people to do this, but with no avail, replace the tab characters with spaces( 4 or 8 spaces will be the usual value). This would give consistent results with different viewers, as different code editors have different tab-size settings and may interpret them differently if you save them just as the tab character.

Also it should be

#include <iostream>
// File Name: transport.cpp
// Activity 3-1
// Author: (aeinstein)
// Date: 05.28.2006

//Activity 3-1:
// "Suppose you have a group of people that needs to be transported on buses and
// …
WolfPack 491 Posting Virtuoso Team Colleague

Anything written between [code] [/code] will be considered as code.

For example

[code]#include <iostream>[/code]

will appear like

#include <iostream>
WolfPack 491 Posting Virtuoso Team Colleague

You have failed to use code tags in the 3 posts you have posted code. Use

tags the next time. There is a watermark in the message edit box telling you about it, so you can't say you didn't know.

WolfPack 491 Posting Virtuoso Team Colleague

well done. Thanks for giving us all the answer. :idea:

WolfPack 491 Posting Virtuoso Team Colleague

Well it compiled and ran for me. But there was a heap error after the distructor was called. The new line after you delete CALLBACK should be

typedef Div (* LPFNDLLFUNC1)(VOID);

I think it is possible to return a object from a DLL. Only I haven't done it.

WolfPack 491 Posting Virtuoso Team Colleague

Try deleting

CALLBACK

from

typedef Div (CALLBACK * LPFNDLLFUNC1)(VOID);

. But I am not sure about returning an object from a DLL. All the DLLs I have written were using C. I will have to search on that further.

WolfPack 491 Posting Virtuoso Team Colleague

Isn't there a testing program to test this DLL? And what are these parts in Red? I get compile errors because of them.

Operation*[m_nSizeArray];

    for(int i=0; i<m_nSizeArray; i++)
    {
            if (i == 0)
                pOperations [i] = new [COLOR="Red"]Sum("Sum"); [/COLOR]  

Next time post your code inside CODE tags.

WolfPack 491 Posting Virtuoso Team Colleague

Post all your code. It will be easier to figure out what is happening using the whole code. The way a compiler builds a C++ function is different from how it builds a C Function. So when you are writing a DLL you have to tell the compiler to compile it as a C Function and not as a C++ function. Usually that is the reason for calling convention errors to occur. Anyway post all your code. Then it will be easier to explain.

WolfPack 491 Posting Virtuoso Team Colleague

But then the message "Press any key to continue..." won't appear...
so I'd just have to make an extra line of code like cout<<"Press any key to continue..."; cin.get();

If you are using Visual Studio, pressing Ctrl+F5 will give you that message in your system locale, without you having to do anything. Pressing just F5 will make the console dissapear without a word. If you run from the console you won't need that message. I dont know about other compilers.

WolfPack 491 Posting Virtuoso Team Colleague

Aren't you using the

extern "C" __declspec (dllexport)

wrappers?

WolfPack 491 Posting Virtuoso Team Colleague

Release or Debug or any other custom configuration you have setup. By default you get the Release or Debug Configuration. This is needed only if you use the /project switch. If you use only the /solution switch, you can just give the solution file and the solutionconfig name and all the projects will be built. reference

WolfPack 491 Posting Virtuoso Team Colleague

Oh I just read the part where you say that you are working in the .NET environment. ThisDocument is a VBA thing I guess. Don't know if it is possible to use in the .NET environment. Will take some time to find that out. Sorry about that.

WolfPack 491 Posting Virtuoso Team Colleague

It has been a long time since I wrote a macro, but if I remember correctly,
ThisDocument.Text gives you the text in the current document. Compile and see.

WolfPack 491 Posting Virtuoso Team Colleague

I would personally go for a Visual Basic Macro or use Visual Basic to write the addin. But maybe this will help.

WolfPack 491 Posting Virtuoso Team Colleague

Try to compile this snippet and tell me if you have any problems. If that works, you could modify it to suit you. The #define switch should be used as it is.

WolfPack 491 Posting Virtuoso Team Colleague

I would use something like

if (sock!=INVALID_SOCKET)
{
     if(send(sock,s,(int)strlen(s),0)==SOCKET_ERROR)
     {
         printf("Sendfailed.%d", WSAGetLastError());
     }
}

and see.

WolfPack 491 Posting Virtuoso Team Colleague

Hi all:

According to the library, recv() will return a zero if the socket is closed, and a SOCKET_ERROR if the socket meets an error.
But when I closed my socket (at least I think I closed it properly), recv() returned a SOCKET_ERROR other than zero. Wondering why?

Thank you whoever help me in advance.

Now will be a good time to use the GetLastError() function.

WolfPack 491 Posting Virtuoso Team Colleague

Looks like you haven't added the second file to the project or have added both files to the project. Remove the first file, and then add the second file. At anycase it is not a bug in your program, but the way you have setup the project for execution.

WolfPack 491 Posting Virtuoso Team Colleague

If send is successful I think it returns the number of bytes sent at that time. YOu can use that and compare with the number of data bytes you wanted to send to see if an error occured or not. GetLastError or WSAGetLastError is only used to get detailed error information, and not for error checking.

Anyway you are saying that the string is displayed only when you disconnect from the server. Displayed where? in the Client( that is your software ) or in the Server ( Java Software)? If it is the Server software, try appending a NULL, '\0' character to your string and see. Maybe the server is waiting for a NULL character as the data termination to display it. Since disconnecting sends a NULL character it is displaying it at that point.

WolfPack 491 Posting Virtuoso Team Colleague

Most probably a missing semicolon somewhere. Can't say much without looking at code. Attach all the project files.

WolfPack 491 Posting Virtuoso Team Colleague

The difference in speed is negligible for most hobbyist programmers. So who really cares- unless you're writing an app for the military?

If you are a hobbyist my advice will be to use Visual Basic 6. It is old but you could write an app in one day that would otherwise take more than one week to write in Visual C++ or maybe Java( I dont know the development time for Java actually). It is really good for RAD. Out of the Java applications Azureus is the only one I know that perform well compared with the C++ programs for the desktop.
But if you are thinking of learning to develop a career in programming for the desktop, the best will be to go with C# (considering the future and present job market), C/C++/managed C++.

I really think that unless the OP says what the purpose of his program is, the replies will be a tug of war between personal preferences.

WolfPack 491 Posting Virtuoso Team Colleague
if (WSAStartup(VERSION, &wsadata) != NO_ERROR)
    {
        WSACleanup();
        return EXIT_FAILURE;
    }

open_socket(serverName, port);

SOCKET open_socket (const char *serverName, const int port)
{
    struct hostent *server = NULL;
    SOCKADDR_IN serverAddress;

    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock!= INVALID_SOCKET)
    {
        server = gethostbyname(serverName);
        if (server == NULL)
        {
            sock = INVALID_SOCKET;
        }
        else 
        {
            char *ip = server->h_addr;
            SOCKADDR_IN serverAddress = 
            {
                AF_INET,
                htons(port),
                {ip[0], ip[1], ip[2], ip[3]}
            };
        }
        if (connect(sock, (SOCKADDR*) &serverAddress, sizeof(serverAddress))<0)
        {
            sock = INVALID_SOCKET;
            printf("Connection failed.");
        }
        printf("Connection successed.");
    }
    return sock;
}

Okay I think it is because you are initializing a newly defined SOCKADDR local variable inside the else branch, but using the uninitialized SOCKADDR variable of the same name. See the lines marked in Red.

Here is a version that would work

#include <winsock2.h>
#include <windows.h>
#include <stdio.h>

SOCKET open_socket (const char *serverName, const int port)
{
    struct hostent *server = NULL;

    SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP );
    if (sock!= INVALID_SOCKET)
    {
        server = gethostbyname(serverName);
        if (server == NULL)
        {
            sock = INVALID_SOCKET;
            printf("GethostName Failed\n");
            return INVALID_SOCKET;
        }
        else
        {
            char *ip = server->h_addr;
            SOCKADDR_IN serverAddress =
            {
                AF_INET,
                htons(port),
                {ip[0], ip[1], ip[2], ip[3]}
            };
            printf("Server Address %d %d %d %d \n", ip[0], ip[1], ip[2], ip[3]);
            if (connect(sock, (SOCKADDR*) &serverAddress, sizeof(serverAddress))<0)
            {
                printf("Connection failed.%d", GetLastError());
                return INVALID_SOCKET;
            }
            printf("Connection successed.");
        }
    }
    else
    {
        printf("Create Socket Failed\n");
        return INVALID_SOCKET;
    }
    return sock;
}


int main()
{
    WSADATA wsadata;
    if (WSAStartup(MAKEWORD(2, 2), &wsadata) != NO_ERROR)
    {
        printf("Startup Failure\n");
        WSACleanup();
        return EXIT_FAILURE;
    } …
WolfPack 491 Posting Virtuoso Team Colleague

Now there are two or three places in your code where the socket may return INVALID_SOCKET, e.g the call of socket, and where the Winsock functions may fail, e,g gethostname(). So why don't you use the GetLastError() function at these places to get the error number when that happens? Then you can search for the description for that error number in MSDN or google, and you will find what is wrong. That will be better than we pointing the error for you.

WolfPack 491 Posting Virtuoso Team Colleague

1. can lists or vectors passed as parameters in a function?
Yes
2. can the lists or vectors be returned ?
Yes

WolfPack 491 Posting Virtuoso Team Colleague

What are some of the pluses and minuses of MFC? I think it is better to do a lot of things that are complicated without it. Any thoughts?

Pluses and Minuses against what? You can get an idea in this reply. It would help if you state what you are trying to program.

WolfPack 491 Posting Virtuoso Team Colleague

Hi,

I am trying to configure a Fedora Core 5 Server for my home network. Can you please tell me if there is a way, and possibly the steps or links, to share the DVD Read/Write Drive installed in the server so that I can burn CD/DVDs across the network using the Windows 2000/XP Client machines.

I am using a Windows 2003 Advanced Server currently and I am burning CD/DVDs across the network using the NeroNet software.

Thanks in Advance.

WolfPack 491 Posting Virtuoso Team Colleague

error C2440: '=' : cannot convert from 'bool' to 'class BST_Node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
root->getLeft() = delNode(key);

error C2440: '=' : cannot convert from 'bool' to 'class BST_Node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
root->getRight() = delNode(key);

BST_Node::getLeft() is a function. You can't assign values to functions. You have to pass values to them. I dont know what you are trying to do. I dont know if you are trying to delete the left node or what. In anycase getLeft does not take a bool value as parameters, which is the datatype returned by delNode. You should be able to work out what the problem is after the first solution was given. In anycase just try

delNode(key);

only and see. I didnt do any testing nor did I read the whole program, so no guarantees.

WolfPack 491 Posting Virtuoso Team Colleague

Try

p->setLeft( root->getLeft() );

and likewise.

WolfPack 491 Posting Virtuoso Team Colleague

Use a function like sprintf or snprintf to create the string you want to display, and then input that string to the MessageBox function. The sprintf function gives you the ability to embed an integer inside a string, by using the %d format specifier. It is similar to printf, the difference is printf outputs the string to standard output, while sprintf outputs it to a character buffer.

WolfPack 491 Posting Virtuoso Team Colleague

program a client to make a connection request from a single server, and display the server name or IP if the connection is granted, and logout.
Use it to make connection requests from each computer in the LAN. You will get a list of computer names where the server is running. You can also program the client program to save the server name if the connection is granted. Then you can have it for future reference.

WolfPack 491 Posting Virtuoso Team Colleague

Here is a similar thread regarding reading an XML file in C/C++.

WolfPack 491 Posting Virtuoso Team Colleague

although interested to know whether anyone else has seen this..

Yep. I have experienced this.

WolfPack 491 Posting Virtuoso Team Colleague

stacking is not something unexpected or errornous in the socket API. the TCP IP protocol only guarantees that the data will reach the destination at the sent order. It may get sent in one try or multiple tries.The problem here is that you are using a 1024 size buffer. If the network IO buffer at the receiving end has data to fill this buffer it fills it with that data. The only way you can eliminate this problem is by using the knowledge of the properties of the data sent. If you know the length you can traverse the buffer using that length. Also you can use a buffer of exactly the required lenght.But even then if there isnot sufficient data, you may get a partially fileed buffer in one try and the rest of the data in the next. If you don't know the lenght, then you will have to use something like the line termination character when sending character data. This is the most reliable.
The best way to handle this problem is to use the 1024 size buffer for data collecting and process this data before displaying it.
Something like coding another loop to find the EOL character in the buffer, displaying the data upto that, and again searching for the EOL....

WolfPack 491 Posting Virtuoso Team Colleague

I have no idea what that means. Seeing as you have taken the time to learn the msdn manual by heart do you think you could code up a sample snippet. :cheesy:

There is an example at the bottom of the page I linked.

Or is using system() ok here?

Personally for something like this I would use system . The overhead for the system call is nothing compared to the effort required to understand and use the CreateProcess function. I would use CreateProcess only if there are some intricate attributes that need to be set in the child processes. But there will be people here who would complain vehemently on the use of system.

WolfPack 491 Posting Virtuoso Team Colleague

Search for CreateProcess

BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);

in the Platform SDK Documentation or MSDN site.

Edit:
Okay here it is.

WolfPack 491 Posting Virtuoso Team Colleague

First prompt is to open wave recorded by therapist's own voice and the second prompt is to open wave recorded by children at home.

Right now what the Play button does is ask for a MP3 file and convert it to wav and load the new wave file. This is to select the MP3 file recorded by the children at home. It is prompting for an MP3 file because that is the format they have recorded it. I did that because you wanted a way to directly convert the MP3 file to wave at the Play Wave button.

As for the wave file pre-recorded by the therapist, since it a wave file, you should create another button to play that file, rather than using the same file usedto load the mp3 file.
For Example
"Play MP3" for the file recorded by the children
"Play Wav" for the file recorded by the therapist.

WolfPack 491 Posting Virtuoso Team Colleague

Hi, WolfPack, thanks for your reply.

Sorry, my mistake. I still have two errors.

error C2039: 'Append' : is not a member of 'CString'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString'
fatal error C1004: unexpected end of file found

Sorry, my programming knowledge is very limited. I understand that I should initialize Append under CString constructor, is it?

Looks like Append is not supported in Visual Studio 6.0.
Replace the line with Append with

waveFileName +=  ".wav";

If you still find that unexpected end of file found error, I think it is because of a missing semicolon or something. You will have to find that yourself.