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

Talking to the comm port in Windows you should use the winsock.h library.

Nope. winsock library is for socket programming, not RS232 serial port programming.

In linux the procedure for writing to the port is exactly the same as writing to a file.

Similar for win32. CreateFile() to open the comm port, then ReadFile() and WriteFile() to read/write to it.

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

sleep takes parameter in seconds -- I think there is a usleep that is in milliseconds.

If you stick to standard c++ code there should not be a problem. But if you use a lot of win32 api graphics functions then you are in deep shit. Most of that is comletely different in the *nix world. My advice is to use a portable library, such as wxWidgets or QT.

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

>>I am assuming that it is the manufacturers catching up with this type of software and finding new ways to stop piracy
Bingo! What you are attempting is illegal.

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

I think that error means that some device driver could not be started. You can get a little more informaton from the sytesm Event Viewer. Log in as administrator account, open Control Panel, select Administrative Tools, then Event Viewer. Browse around there to see if you can find something that explains the error.

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

Did you write that code you posted or not? My guess is you got it from someone else. Study the code and think about what it is doing. Then see if you can see how to rearrance a few lines to make it do what you want it to do. If you don't understand the program you posted then I don't know how we can help you.

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

>>can you give me the code that your talking about please.....
I could, but I won't. Try to do this yourself so that you will learn something. Afterall, isn't that what school is all about?

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

your coding style needs a lot of improvement.
1) add { and } for clarity and to tell the compiler what lines go inside the loop. The way I placed it below is how your compiler would have treated it, which is probably not what you intended.

2) iostream.h is obsolete. Current c++ standard header files do not have extensions. But if you are using an ancient compiler such as Turbo C then you don't have any other choice but the use those obsolete header files. If you can you should get a current, free compiler.

#include <iostream>
using namespace std;


int count,a[2][2]={0,2,2,3}; //primary matrix


int main() {
    for(int i=0;i<5;i++)
    {
          for(int j=0;j<5;j++)
          {
                if(a[i][j]==a[i++][j++])
                       count++;
          }
      }
     cout<<a[i][j]<<count;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ill have this triangle but im using SPACING to create this......
That's what you're supposed to do. Just reverse the order of the spaces and start, and you should get what you want.

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

You can gain as much memory as you want if you create DLLs.

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

Didn't your momma ever tell you that "can't never did anything". What's the first thing you have to do? Answer: write a program with main() function. Next: create a loop that counts from 0 to 5. Do you know what a loop is? If not, then read your textbook and it will tell you with examples.

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

post the code you have written and we'll try to help you.

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

You should use the functions on MS-DOS _find_first_file() and _find_next_file(), or MS-Windows win32 api FindFirstFile() and FindNextFile(). *nix use opendir() and readdir(). There are examples of those functions all over the net and in DaniWeb's Code Snippets board.

If you don't want to use those then why not something like this?

int id = 0;
for(id = 0; id < 9999; id++)
{
    char filename[255];
    char line[100];
    sprintf(filename,"passenger %04d", id);
    ifile = fopen( ... );
    if(ifile != NULL)
    {
            while( fgets(line, sizeof(line), ifile) )
                  fprintf("%s", line);
            fclose(ifile);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of examples. For instance

class Person
class student : public person
class teacher : public person
class university : public student, teacher

class animal
class dog : public animal
class cat : public animal

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

>>I don't have time!!!
Such is the life of a programmer -- we all feel that way frequently, especially when we don't start coding until just before the program is due to be shipped. That's when you load up on peanutbutter & jelly sandwitches, then go for a 24-hour day at your computer.

Write your program in very small steps. What's the first thing you have to do? write the main() function and create an array! write that and get it to compile cleanly before going on to the next step.

Do in small steps and you will soon have your program written.

Post back here with the code you have written and with more specific questions. Crying will not help.

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

If you crack my program and I find out about it then I will sue your ass off so hard you will owe me for the rest of your life. And if you are selling/giving it to others you might also get a little prison time. That's exactly what's happening in the music industry, and Microsoft does it on occasion too.

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

It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff).
if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in these two lines of code.
Right solution (one of);

while (cin && cin.get() != '\n')
    continue;
// or simple
while (cin && cin.get() != '\n')
    ;

The correct solution to clearing the input stream is explained here.

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

What do YOU tink they mean?

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

Have you compiled the samples that come with the DirectX DDK?

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

read the weight from where? Does your computer have a scale attached to it? Or do you get that info from typeing it in on the keybaord (most likely) ?

Do google to find the math algorithm for converting ounces to metric units. "metric tons" is a awful lot for a box of cereal :) Or you are buying enough cereal to feed an army. If one box of cereal weighs 16 ounces (one pound) then it would take 2,000 boxes to get one short ton. For other conversions see here.

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

>>Do you have much experience with interfacing with devices other than the cmd line?
I have written programs to talk to robots on factory assembly lines, some via PLC (program logic controller) attached to RS232 serial port while others attached directly to the com port. Each one was unique and required manufacturer's programmer's book to get the set of commands and how to interface with it. But that was about 12 years ago, so my knowledge has slipped quite a bit.

MS-Windows is NOT a real-time operating system, so don't expect real-time instant communications through the com ports. When dealing with external hardware the computer needs to be dedicated solely to that application -- no one should run any other applications, such as browswer, windows word, or other non-related programs.

You will want to create a listening thread(s) to do nothing more than listen for incoming data. You install that thread function when you set up the communications port so that the Microsoft com driver can call your listening function as data arrives at the port. If you don't do this then your computer is likely to lose data; poling for the data is not sufficient because UARTs can only hold about 16 bytes.

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

I had the same problem you have with your program too. But by comparing the example program Sample1 I found that you need to include two libraries -- libmysql.lib and mysqlpp_d.lib (they probably have *.so file extensions on your system) After adding that 2nd lib the program linked ok.

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

Are you able to compile/link the example/test files that come with the MySQL++ distribution? I have the distribution for MS-Windows, using a different compiler, and have no problems with the sample/test programs.

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

MS-Windows Communications Reference here. I think it even has examples.

>>which is connected to the computer system via the "ninth" COM port
Does that mean the computer has a COM port expansion board installed, there are several 8, 16 and 32 port boards and each has a device driver so that your program can reference the ports as COM1, COM2, COM3, ... COM32. Just use the port number in the CreateFile() statement (see the examples previous linked).

>>How can we transfer information to and from the GPS device
I have no idea about how to communicate with the GPS device -- you will have to read the manufacturer's programmer's reference documentation for that. But you set up the com port's parameters via the functions/examples previously described.

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

thanks.

I will read the textbook.

Oh what a great idea! :icon_idea: Someone going to actually read his textbook :)

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

Here are some more options you might consider.

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

Hey sampson: don't you guys ever run an antivirus program on your computer? I have one running whenever I boot my computer and have never in the past 10 years had a problem. The antivirus program won't allow a download if the file contains a virus. There is no excuse for catching a computer virus today (except in rare cases where its a new virus).

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

Just a simple text file will do -- I doubt your instructor wants something as complex as an SQL database.. Use ofstream to output the data and ifstream to read it back. Both are declared in the header file <fstream>.

If you don't yet know how to use those two c++ classes then I'd suggest you read your textbook because it most certainly covers that topic. Also look in the Code Snippets board (link at the top of every DaniWeb page).

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

>>How would I do this? How to I tell the random generator to only put the location in 70,233, 204,146 or 46,46?

#include <ctime> // for time() function
int main()
{
    // seed the random number generator
    srand( (unsigned int)time(0));
<snip>
   // somewhere in your program do something like this
   int nms[] = {70233, 204140, 4646};
   int location = nms[ rand() %3];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've done it once in nearly 800 games. .

Oh how nice of M$ :) Glad to know it will take the rest of my life to beat that game with 0 points.

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

>>time_t now = time(res[1]);
That's wrong -- the parameter to time is a pointer to a time_t object. I don't know what you are passing but it isn't time_t*

If you are attempting to convert the date/time in the result set to time_t, that is the wrong way to do it. win32 api FileTimeToSystemTime() will convert that FILETIME object to a SYSTEMTIME structure, which is similar to struct tm, but has milliseconds, and you can easily access the month, day, year, hour, minutes, seconds, and milliseconds.

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

maybe something like this, which will leave String_received untouched. This allocates new memory for Seg_string, so don't forget to free() it sometime later after you are done with it.

char* Seg_string = 0;
char* Single_Char = Get_Char_pc();
Seg_string = malloc(strlen(String_received) + strlen(Single_Char) + 1);
strcpy(Seg_string, String_received);
strcat(Seg_string, Single_Char);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't understand your reasoning here, Mr. Ancient Dragon. You knew that in C is not necessary to typecast the return of malloc. You knew something must be wrong with it. And then you go ahead and implemented a bad practice version for the OP.

C compilers do not complain about the return value of malloc() as the op reported. Only c++ compilers do that, which is why I made that statement. So I assumed the op really intended to compile the code with c++, not c. Otherwise I agree completly with your comments. Had the op compiled the program as *.c file this would not have been an issue.

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

>>Seq_String=strcat(&String_received,&Single_Char);
That is a huge problem. String_received is already a pointer, and you are passing a pointer to a pointer, which is wrong. Also, if Single_Char is what that name implies (defined as char and not char*) then you can't use strcat() with it because strcat() expects a null-terminated array of characters.

Third: what is Seq_String? you don't need it because after strcat() is done String_received will contain the entire new string. All strcat() does is return either String_received or NULL, depending on error or not.

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

>>Also can anybody explain me the differance between Visual C++ and Visual C++.NET?
That's an easy one -- none. Two different names for the same compiler (assuming the same version produced since 6.0).

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

You need to do some typecasting to remove those errors. Apparently you are compiling a c++ program, not C because in c++ the return value of malloc() must be typecast, but not in C. Here are the corrections -- I had to fake it on the data structure.

int main()
{
struct d data;
const size_t BUFSIZE = 1048576;
size_t datasize = 0, nextpos = 0, freepos=0;
char *constDataArea= (char*)malloc(BUFSIZE);
if (nextpos > BUFSIZE)
{  
	printf("OUT of memory\n");
	exit(0);				
}
datasize=sizeof(data.Short);
nextpos = freepos + datasize;
memcpy(constDataArea+freepos, (char *)&data.Short,datasize);
freepos=nextpos;
if (nextpos > BUFSIZE)
{  
	printf("OUT of memory\n");
	exit(0);				
}
datasize=sizeof(data.Double);
nextpos=freepos+datasize;
memcpy(constDataArea+freepos, (char *)&data.Double, datasize);
freepos=nextpos;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>You see, I'm trying to move the actual picturebox, not the window
Everything is treated as a window -- combobox, listbox, picturebox, buttons, checkboxes -- all those are windows.

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

>>I want to make a real time 3d aquarium'
Not possible on MS-Windows because the os is not a real-time os.

When you buy VC++ compiler you get all the present and future service packs that they produce for that compiler.

I would imagine you can write your program with any modern 32-bit compiler. OpenGL might be a good (and free) graphics library and, as far as I know, works with most compilers.

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

must be something in your code because template classes are passed by reference all the time -- most common is probably fstream.

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

all you had to do was add using statements at the top of the program, and it compiled/linked ok for me.

//pointerDataClassIMP       ; this is the implementation file
#include <iostream>
#include "pointerDataClass.h"
using std::cout;
using std::endl;
using std::cin;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know if samples are in iso or not -- my guess is not.

Also check this Scribble tutorial.

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

Will you zip up that directory and attach it so that I can check it out? My guess is that you didn't make the project correctly. But that is just a guess.

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

Linky Also check the DVD because it probably has several example programs.

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

How about *.obj files? *.o and *obj are the same thing, depending on what compiler you use.

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

print out the value of the string before entering that loop so that you can verify it is correct or not.

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

Looks like your makefile is incorrect. delete all the *.o files in your project directory and try again.

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

This works for me

int main()
{
    char Seg_String[] = "2000;ON_0;1000;ON_2";
    char* ptr = strtok(Seg_String,";");
    while(ptr)
    {
        printf("%s\n",ptr);
        ptr = strtok(NULL, ";");
    }
    
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete the semicolon on line 4. defines don't end with a semicolon. It would be better to use a const int instead of that #define const int ingresos_totales = 5;

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

what is the error message? Check the spelling to make sure it is spelled correctly -- don't assume.

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

CDC is a Microsoft MFC (Microsoft Foundation Class) c++ class. The only way to get it is to buy with your $$$ the Professional version of Visual C++.

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

sounds like homework -- did you look it up in your text book ? Errors tell you there is something wrong with your program, and you have to correct them before the compiler can produce the final executable program.