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

what do you mean?

I guess you didn't read my previous post. casting only makes it compile -- that doesn't mean it will actualy work. Did you test your program, something similar to what I posted? If not, then you are in for a big supprise.

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

Mr. Dragon, wont this work or do the same trick or the const nature of the returned null terminated char array pose some problems ?

It will compile but displays garbage at runtime because the string returned by substr() is only temporary object which must be copied someplace else such as another std::string object or char array.

#include <string>
#include <iostream>
using namespace std;

int main()
{

	string str = "Hello World";
	const char *p = str.substr(2,4).c_str();
	cout << p << endl;
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

std::string.substr() returns another std::string.and you can't mix C and C++ like that. you would need to allocate space for the substring

char * str;
string str2 = "hello";
string str3; 
str3 = str2.substr(2,4);
str = new char[str3.length()+1];
strcpy(str,str3.c_str());

C isn't nearly as kind to you as c++.

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

I would use getline() without the deliminator to that it will read the entire line up to the CR/LF into a string, then parse the string for commas.

[edit] Yup, same as what WolfPack posted [/edit]

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

This is now the THIRD TIME I've told you that you have to FOLLOW THESE INSTRUCTIONS . PAY ATTENTION TO Steps 3 through Steps 5.

On my computer the SDK was installed here:
D:\Program Files\Microsoft Platform SDK\Lib

And yes, odbc32.lib is there. Check your computer to convince yourself that the file is on your computer too.

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

I figured you could handle the rest of your assignment yourself. But don't use what I posted without knowing what it did and how it was done -- most instructors will be able to recognize when a student just copied code from the web. There are as many ways to accomplish your project as there are programmers to write it. You instructor will know if you turn in an assignment that uses techniques beyone your current level of understanding.

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

try argv[0]

int main(int argc, char *argv[])
{
  printf("%s\n", argv[0]);
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually, since the op is apparently writing a c++ program (cout is c++) I wouldn't use any of the approaches presented so far -- use std::string and its substr() method to split the original string into 4 pieces. then use std::stringstream to convert them to integers. But maybe that is too advanced for him and may not meed the requirements of his assignment.

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

I don't normally post complete homework solutions, but since everyone else is, here's my 2 cents worth

#include <iostream>
using namespace std;

int main()
{
	const char str[] = "1234567891234567";
	char array[5][5] = {0};
	int nums[5] = {0};
	char *ptr;
	int numindex = 0;
	int i, total;
	ptr = array[0];
	for(i = 0; str[i] != 0; i++)
	{
		if( (i > 0) && (i%4 == 0))
		{
			++numindex;
			ptr = array[numindex];
		}
		*ptr++ = str[i];
		nums[numindex] = (nums[numindex] * 10) + str[i] - '0';
		
	}
	++numindex;
	total = 0;
	for(i = 0; i < numindex; i++)
	{
		cout << nums[i] << " ";
		total += nums[i];
	}
	cout << " total: " << total << "\n";
	for(i = 0; i < numindex; i++)
	{
		cout << array[i] << " ";
	}
	cout << "\n";
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you download and install the Windows Platform SDK as described here ? Make certain you follow the instructions in Step 4 which tells you how to set up the compiler to see the files in the SDK. If you did that right you should have no problems compiling the project I posted.

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

>>there is no data from database written.

Read you program again. Where does it even attempt to write anything to the text file? Where does your program call readFromDB() to get the row from the table? You program consists of two functions, one function that just opens a file then immediately closes it. And a second function that opens the database and executes a query -- it just ignores the result set. Nowhere does your program put those two functions together. You need to do something like this

OPEN THE TEXT FILE FOR WRITE
OPEN THE DATABASE
QUERY THE DATABASE
CALL mysql_field_count() TO SEE IF THE QUERY RETURNED A RESULT SET
FOR EACH RESULTSET ROW (one of the mysql_fetch??? functions)
   WRITE RESULT ROW TO TEXT FILE

CLOSE THE DATABASE
CLOSE THE TEXT FILE

You need to be familiar with the mysql docs if you want to write a program that queries a mysql database.

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

read the manual! fgetc() does not return NULL when end-of-file. It returns EOF.

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

On MS-Windows os, look in C:\WINDOWS\system32\drivers\etc for hosts and services files. These two files will tell you which ports are used or available for use, but doesn't say whether they are accessible -- some may have been blocked by company policy or filewalls. *nix systems have similar files, but I don't know the standard location for them.

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

there is no standard naming convention that all programmers use, normally when you go to work for a software house the company you work for will have a set of standards that you must follow. Lacking that, you can use whatever you like.

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

VC++ 2005 Enterprise, but it will cost you about $2,000.00 :eek:

also, read this thread

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

>>and it worked fine but for some reason now it doesnt do what the program tells it to do'

Yes, it does do exactly what you told it to do. But that may or may not be what you want it to do. :mrgreen:

major problem is that you are using the = operator instead of == operator in the if statements

if( taco == 1 )
   /blabla
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If it is running Microsoft Windows 2000 or XP, why can't you just install it like any other program?

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

1. do not use feof().
2. your program is mixing binary file read with text file writes. If the file is truly a binary file then simply using fprintf() to write it to another file is not what you want to do.

char buffer[255];
size_t nBytes;
while( (nBytes = fread(buffer,1,sizeof(buffer),fp_infile)) > 0)
{
    fwrite(buffer,1,nBytes,fp_outfile);
 }
fclose(fp_infile);
fclose(fp_outfile);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you already said you need a loop, so I suppose you know how to do that. Inside the loop you need to format the filename based on the loop counter.

char filename[255];

// assum loop counter is variable i

sprintf(filename,"file%d.jpg",i);
utput.open(filename, ios:out|ios::binary); // output]

There are a couple of other ways too, but I think the above is about as simple and easy as it gets.

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

getch() returns an int, not a char. And there is an open parenthesis missing in the if condition.

int c; 
if( (c==getchar())!='\n')
<snip>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

my guess is that either (1) you are attempting to run a program that requires W2K or XP, or (2) the program has some bugs, possibly buffer overflows, that is causing it to scribble all over memory.

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

>> do i need the sql express to use Vc++?

No.

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

I don't know if just simply copying that dll will work or not.

you might review the system requirements to make sure your computer meets or exceeds them

Did you have a previous beta version of the compiler installed? If yes, did you uninstall it before installing the newest version as noted in the Microsoft download link?

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

what version of MS-Windows? I think it must be either 2000 or XP.

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

what version of vc++? there's only a dozen or so versinos :)

Here is one solution -- I have no idea whether it will work for you or not

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

<<<<<<<<<<<Dialog.Cpp>>>>>>>>
Preview * p=new Preview();
p->GetDC()->TextOutW(1,2,_T("rxg"));
i think add char to p;
Debug no Error,but run Error
how to add char to TextOutW function in p

sorry,My English isn't good
thank:)

after calling new you have to call its Create() method. I don't recall all the parameters, but you can find them at www.microsoft.com

Preview * p=new Preview();
p->Create( <snip> );
...
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The above statements is illegal .

No it isn't illegal --I use similar constructs frequently to copy data from destination to source. Example:

char buf1[20];

char* p1 = buf1;
char *p2 = "Hello World";

while(*p2)
  *p1++ = *p2++;
*p1 = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

name even one case where the programmer has control over gets(). The standards committee probably left it in because taking it out might break a lot of programs that already use it. The statement you quoted is just a bunch of frabridated bull****.

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

I could not understand why do we need fstream object, where the purpose is only to write to the file.

because the program can't write to a file without it. It probably opens the file once and leaves it open for a very long time, and passes the fstream object around to other methods in the class. I don't like leaving a file open for long periods of time -- my logging function closes the stream as quickly as possible to (1) reduce possibility of corrupt file in case of abnormal termination of the program and (2) other programs, processes and people can easily access the file.

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

>> there are no "always do" or "never do" rules

Never ever use gets():mrgreen:

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

speed is sometimes much more important than modularity or maintainability. I worked several years on a program that had to get data real-time from barcode readers on packages as the packages moved along an assembly line. Then the program had to look-up data in a database whose key was the barcode, format the data, and send it to a large-character printer that would print information on the side of the packages when they moved past the printer. All that had to be done in less than 1/2 second and management thought that was too slow. We even resorted to assembly language to squeeze out every millisecond we could.

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

If you know how to do file i/o (reads and writes) then the problem is pretty simple. Just open the main file for reading (binary mode) then create a series of small files (open them only one at a time) that will store XXX number of bytes. When the output file contains the desired number of bytes, close it and open another output file. Suggestion: give the names of the output fles some sequential identifier to make it easy for the fella on the other end of the TCP/IP to put the file back together again. For example "file001.txt", "file002.txt" ...

If you do not know how to do file i/o you will need to read a tutorial or text book for introduction.

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

First, the result is undefined, so all bets are off when you come to...

you mean the result of adding two numbers whos sum will not fit in the integer is undefined. Of course this is not a total disaster -- just use an integer that can hold larger numbers, which you would be forced to do if you were writing a checkbook program for Bill Gate's back account:cheesy: In that case, c and c++ would not be the desirable computer language. Fortran or C# might be better.

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

Yes, I will agree there are some cases where my comparison function doesn't work right -- when either or both numbers are negative. Its not due to some exotic bug or problem with integer overflow but an elementry property of math (subtractiing two negatives is really adding them and that will result in a value with the wrong sign returned to qsort). So my quick comparison function does not work for all values. S.O.S.'s function is better afterall .:)

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

Actuall I had forgotton about that discussion -- but if subtracting two integers were really that much of a problem then no computer program would work. So I just dismiss it as a non-issue and non-problem. It isn't really worth the effort to even think about -- wasts too many brain cells (and I need all I can get). It might only be a problem in some remote unlikely os that nearly nobody uses.

returning the difference between two integers will work correctly in probably 99.999999% of all operating systems. So who reall cares whether it may or may not result in some obscure problem. I don't stay awake at night thinking about such problems. And neither should anybody else.

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

Except that that version is buggy.

where is the bug? It compiles ok for me and returns a value similar to strcmp().

The comparison function must return an integer less than, equal to, or greater than zero ...

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

just an alternate compare. qsort() doesn't care about actual values, just cares about 0, < 0 or > 0.

int compare (const void* source, const void* dest)
{
   return ((List*)source)->value - ((List*)dest)->value;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you did not create the project correctly. I recreated the project and had few problems compiling it. I don't know if it works or not, but it compiles ok.

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

Hummm... I Had No Luke

I Still Get

Program database manager mismatch; please check your installation

sorry, I have no idea what the problem is. zip up the whole project and attach it. But delete the debug and release directories first.

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

Thank You Now I Have ANOTHER Error When Will They Stop!

c:\program files\microsoft visual studio\myprojects\bypass memory dll\bypass memory dll.cpp : fatal error C1902: Program database manager mismatch; please check your installation

you will have to do a little research on that one.

>> When Will They Stop!
When you get all the problems fixed.

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

>>Of course, once you do this, they will attach themselves in some leech-like manner to YOUR email address and you'll never get away from their endless questions

That's one reason I have PMs turned off.

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

read the description of the open flags -- one of the allows both read and writes and your program only opens the file once.

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

>>error C1083: Cannot open precompiled header file: '.\Debug/Bypass DLL.pch': No such file or directory

Ok that one is pretty easy to fix. Turn off precompiled headers. Select menu item Project --> Properties (at the bottom of the meu list). Expand the "Configuration Properties" button, expand the c/c++ button, then select "Precompiled Headers" item. Change the "Create/Use Precompiled Header" to "Not using precompiled headers"

[edit]Or ... just do a full rebuild so that the compiler will recreate it.[/edit]

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

but then it wont make dll

:cheesy: :cheesy: that's what we have been telling you for two days now! you do not have (or at least you have not posted) all the code that is necessary to put that dll together. you can not just ignore the other errors, they must be fixed.

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

>> Error executing cl.exe

Just ignore that one -- it only means your program failed to compile and link correctly. Just fix the other reported errors.

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

I know there have been lots of those written -- google will show you a few, such as this one. It was written for dumping contents of RAM but you should be able to easily modify it for files.

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

I know its possible to write binary files because I've done it hundreds of times, and so has almost everyone else.

This works for me.

#include <stdio.h>

#define MAX	1

typedef struct {
	short int key;
	char name[21];
	char symbol[6];
	float price;
	float high;
	float low;
	short int ratio;
} STOCK;

void get_data(STOCK *);

int main(void) {

	FILE *fp;
	STOCK data[MAX] = {	{
			{1000}, {"nasdaq"}, {"NAS"}, {100}, {100}, {50}, {2}
		}
	};
	// if the file does not exist, then create it
	if(!(fp = fopen("stockdata.dat", "rb")) )
	{
		if(fp = fopen("stockdata.dat", "wb")) { 
			fwrite(data, sizeof(STOCK), MAX, fp);
			fclose(fp);
			fp = fopen("stockdata.dat", "rb");
		}
		else
		{
			printf("can't write to file\n");
			return 1;
		}
	}

	STOCK test[MAX];
	fread(test, sizeof(STOCK), MAX, fp);
	fclose(fp);
	printf("%hd\n", test[0].key);

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

you will have to be a little more specific about the requirements -- a "Dump tool" can mean almost anything. My interpretation would be a program that displays the contents of database tables. Yours might be something else entirely.

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

The first place to start your research is probably google. It can often find answers to problems quickly, and sometimes not too.

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

you need to download the Windows Platform SDK because Visual C++ 2005 Express does not include it by default. Go back to the download page and you will find the link at the bottom of the page. There are also instructions on how to set up the compiler to use it (you have to add a few paths in the compiler's settings).

In case you can't find it, here is the link

once you get it to compile, don't expect me to tell you how to use it -- I haven't the slightest clue, so you are on your own from there on.

[edit] The errors you posed indicate that you are missing code -- the variables are declared someplace else. That is one of the grave dangers of attempting to compile someone else's code when you don't have a clue what you are donig. There is no way anyone can help you because of the missing code.[/edit]