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

>>but it's not working
What exactly does that mean? Did you get compile error messages? Yes, then post a few of them

>>int gdriver=DETECT,gmode;
That looks very questionable -- why use the comma operator ?

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

dude i knw hw to speak/explain in english...
n also the prblm m facing...
may b u r not undersatanding

obvsly nt sc y cnt wr a dcnt sntce.

jonsca commented: Nice +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I thought you said you were going to sleep :)

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

Good night :)

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

function FileToArray is missing closing } for the switch statement.

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

Can't help you if you don't post the complete code you are trying to compile.

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

line 7: variable i should be int, not char because you want to use it as an index into an array. Although char might work, but int is more common to use for that purpose.

line 9: you used the wrong variable -- use varuale n, not i. afile >> n

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

i using windows xp i install the turboc when i click tc but it open and close immediately

Good :) Now get yourself a newer free compiler such as Code::Blocks/MinGW or VC++ 2008 Express.

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

Didn't your mommy ever tell you that can't never did anything???

Post your most recent attempt.

>>I hav no experience using char in switch.
Well, this will give you a chance to get the experience

char n;
infil >> n;
switch(n)
{
    case 'F':
      //blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) To get more than one character for name you have to declare an array of characters, like the code below

struct MaleStudent
{
	char name[40];
	int mark1;
	int mark2;
	int mark3;
};

2) that is not what you posted in your original post.

The first character in the file is either the letter F or M, not an integer, so the operation on line 8 will fail and that function will do nothing. You will have to read the first byte as data type char not int then switch on either 'F' or 'M' (lines 12 and 18)

lines 14, 15, 16, etc: you can not use endl on an input file. delete "<< endl" statements on those lines and others like them.

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

m not getting hw to compile it using notepad++

i know tis not a compiler...
n m asking to tell me how to make notepad++ to compile c++ program

No one can help you if you yourself don't know what you want. Maybe you are just having problems trying to explain it in English language??

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

1) line 13 and 21 only reserve one character for name.

2) function FileToArray() does nothing but open and close the input file. What good is that??? I expected to see some code that read the file into the structure members.

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

zip up the project and attach it to your post. But first delete all compiler-generated files, especially those huge precompiled header files.

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

Well, I am using VC++ 2008 Express and the program I posted compiles without any errors or warnings. I can only guess that you didn't set up your project correctly. Try creating a new console project, then change the project properties so that it doesn't use UNICODE.

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

these programs can b compiled using notepad++..theres no need to chage lappy...
jst that m not getting hw to compile it using notepad++

As others have tried to tell you -- Notepad++ is not a compiler. I think you can tell notepad++ how to run a a compiler, but notepad++ doesn't compile anything itself.

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

did you include windows.h as I posted it???

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

Here is the complete program

#include <windows.h>



int main() {
HANDLE comports[10];
comports[0] = CreateFile("\\\\.\\COM6", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);	
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 21: That is opening the file in text mode, not binary mode. You need to add ios::binary flag ifstream file("monkey.c3d", ios::binary); That is most likely why you get the unexpected problems you are experiencing.

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

That first code snippet compiled ok for me after adding another \ escape character at the start comports[0] = CreateFile("\\\\.\\COM6", /* blabla */

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

Nic -- I really have no idea what in the world you are talking about. Reptilians?? There is no such thing except maybe in some sci fi flicks. If there is intelligent life out there somewhere then it might or might not look like those reptilians. Whatever they have to do with God I have no clue.

Grim: agree -- that was a horrible-looking web site. It hurt my eyes to read it (actually I didn't read all of it, just the first couple sentences.)

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

zip up your entire project and attach it to your post. Delete the compiler-generated files, especially those precompiled header files.

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

you need to include windows.h, not ole32.h. Here are the changes you need to make to stdafx.h. Notice I deleted the line I suggested previously because windows.h forces all the necessary libraries.

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

// TODO: reference additional headers your program requires here
#include "windows.h"
#include <stdio.h>
#include <iostream>
#include <tchar.h>
#include "bridge.h"
using namespace std;
Nick Evan commented: Nice one :) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Circular dependencies. You can only do it by using the two class pointers because otherwise the class must be fully defined before it can be referenced.

class Actor;
class Environment
{
  // blabla
void add_actor(Actor * act);

std::vector<Actor*> actors;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post code so that I can try it out.

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

Here is a thread about the same problem. You can sometimes get specific help by googling for the error message.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Agni commented: Nice article..!!! +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

menu Project --> Properties (bottom item of the popup menu) -->expand the Configuration Properties tab --> Linker --> Input. The first line on the right side is "Additional Dependencies". Add the name of the library there.

An alternate way to do it is to add this near the top of one of the *.cpp files in your project #pragma comment(lib, "ole32.lib")

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

Attached are the two projects I created, under a common folder named dvlp

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

>>Was that code to read the dll
Not sure what you mean by that. C/C++ programs don't read DLLs but just simply call the functions.

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

You must have something setup wrong because it worked ok in the dll for me. Here is the main() that I used.

[edit]Note: make sure you do not have more than one copy of that dll on your computer! [/edit]

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>

#pragma comment(lib, "testdll.lib")
#define DLLEXPORT __declspec ( dllimport )
DLLEXPORT std::string *explode (std::string exploder, std::string original, int limit=0);
DLLEXPORT void FreeResult(std::string* result);


int main() {
	std::string *tmp;
	tmp=explode(".","a.b");
	std::cout << tmp[0] << "--" << tmp[1] << "-" << tmp[2] << std::endl;
    FreeResult(tmp);
	system("PAUSE");
	return 0;
}

And this is the dll

#include <iostream>
#include <sstream>

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

#define DLLEXPORT __declspec ( dllexport )
DLLEXPORT std::string *explode (std::string exploder, std::string original, int limit=0) 
{
	std::string tmp;
	tmp=original;
	int num, loc, x, limiter;
	limiter=0;
	num=1;
	while (tmp.find(exploder)!=std::string::npos) {
		if (limiter==limit && limit!=0) { break; }
		if (limit>0) { limiter++; }
		loc=tmp.find(exploder);
		tmp=tmp.substr(loc+exploder.length());
		num++;
		}
	std::string *result;
	x=(num+1);
	result = new std::string[x];
	std::string s;
	std::stringstream out;
	out << x;
	s = out.str();
	result[0]=s;
	num=1;
	tmp=original;
	while (tmp.find(exploder)!=std::string::npos) {
		if (limiter==limit && limit!=0) { break; }
		if (limit>0) { limiter++; }
		loc=tmp.find(exploder);
		result[num]=tmp.substr(0,loc);
		tmp=tmp.substr(loc+exploder.length());
		num++;
		}
	result[num]=tmp;
	return result;
}

DLLEXPORT void FreeResult(std::string* result)
{
    delete[] result;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what version of the compiler IDE are you using?

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

Your program needs to link with Ole32.lib. Check the project setting of your compiler to see that it is doing that.

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

Why would you say that? Most experienced C/C++ forum posters are stuck spending way too damn much time trying to unexplain "arrays are pointers".

The only way to pass an array between functions is via pointers. I was just trying to be brief in the context of this thread.

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

What two parameter strings are you passing to that function so that I can test it ?

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

AFAIK CTrace is only supported on *nix. For your compiler just learn to use its excellent debugger.

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

>>Does anybody know the basics behind making a string array without a pointer?

Arrays in C and C++ are always pointers.

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

I am unable to find out the list:(

what list? The links we posted are youtube videos.

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

Didn't you bother to look at the problem line (line 44)?

>>result[0]="1";

result is a std::string, therefore you can not set the first character to a string. It should be result = "1";

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

Just occurred to me you'll probably need a LoadLibrary("PathToDll") call there too.

\

That is only necessary if you want to use GetProcAddress(). The Windows OS program loader will auto load the dll when it starts the program.

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

change line 4 to this: #define DLLEXPORT __declspec ( dllexport ) Now you will have a normal c++ function, which of course can not be called by any C program. But you will still want to change the return value so that it returns std::string instead of std::string *.

cwarn23 commented: Great help and advice +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't notice you had extern "C" in that. In that case you can not return a std::string object, nor can any of its parameters be std::string because that is c++, not C.

What I would do if add another parameter for a buffer that is allocated in main application program, much like many of the win32 api functions do. This means you will also have to do some re-coding of that function to remove references to std::string.

DLLEXPORT BOOL explode (char* result, size_t resultsize, const char* exploder, const char* original, int limit=0) {
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

memory allocated with new or malloc() in a DLL can not be deallocated by the main program because the memory has to be deallocated in the DLL. The same with memory allocated in the main program has to be deallocated there, the dll can not do it. The reason is because they are from different memory pools.

So the thing you should do for that function is to return the std::string object, not a pointer to it (just remove the star) and delete line 38. DLLEXPORT std::string explode (std::string exploder, std::string original, int limit=0) { Here is another thread about that discussion

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

Energy cannot be destroyed , it can only change forms

And the Earth is still flat :) Scientific thought tomorrow may prove that statement false.

God being all-powerful could have made Earth, the universe, physics, science, everything give humanity (and any other intelligent life elsewhere in the universe) the exact answers we've found.

Which, of course, proves the universe is a lot older than 6-10,000 years. Or did God contradict himself? I doubt that, instead it is man who misunderstood the teachings in the Bible.

Who's god?

There is only one God -- All those others you may have heard about are just variations of the same God.

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

did you try it on the sites you can not access ?

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

The problem might be your isp -- I am running 64-bit Win7 and was able to connect to those sites (didn't try them all)

In a command prompt try this: tracert [url]www.daniweb.com[/url] or any other site you want.

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

please some guru provide a correct reason on this because
it is not as simple as it looks

There is no one correct reason. All the reasons mentioned in this thread are correct. There is another integer type -- char which is a one byte integer. And of course there is the 64-byte integer known as long long, or sometimes __int64.

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

An interesting and mind-boggling thread. When God created the universe 6,000 years ago He made it look like the universe was 16 billion years old. Yea, right :)

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

while ( letter_box[i-1] !=SENTINEL); //how do i correct this???? char is just a one-byte integer, and has both negative and positive values.

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

Shall I repeat myself -- use GetModuleFileName() -- this will return the full path where the program that is currently running was started. If you are trying to get the path of another program then this will not help you.

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

If you are trying this on a school's computer then your school may have locked you out of certain folders, giving you only read-access to c:\program Files and c:\windows. They don't want you screwing around with those folders, possibly adding viruses or deleting important files.

The del command don't work unless you put quotes around the path system("del \"C:\Program Files\Windows Live\Messenger\msnmsgr.exe\"")