-
September 6th, 2010, 12:09 PM
#1
C++ Newbie, Need Help!
Hey Guys, So I am trying to implement a socket program that will allow me to transfer data from a machine and monitor it remotely. Having issues with a particular part of this program. I am a newb to programming and I would greatly appreciate any help. The error I get is:
Unhandled exception at 0x0040196b in haas.exe: 0xC0000005: Access violation reading location 0x00000000.
Call Stack:
> haas.exe!main(int aArgc, char * * aArgv) Line 46 + 0x3 bytes C++
msvcr100.dll!_initterm(void (void)* * pfbegin, void (void)* * pfend) Line 873 C
Code:
#include "internal.hpp"
#include "haas_adapter.hpp"
#include "server.hpp"
#include "string_buffer.hpp"
int main(int aArgc, char *aArgv[])
{
int port = 7878;
int i = 1;
bool debug = false;
bool positions = false;
while (aArgv[i][0] == '-' && aArgc > 0)
{
if (aArgv[i][1] == 'd')
debug = true;
else if (aArgv[i][1] == 'p')
positions = true;
else
{
printf("Invalid option: %s\n", aArgv[i]);
printf("Usage: %s [-dp] <Serial_COM> [port]\n", aArgv[0]);
exit(1);
}
i++;
aArgc--;
}
if (aArgc > 2)
port = atoi(aArgv[i + 1]);
/* Construct the adapter and start the server */
HaasSerial *serial = new HaasSerial(aArgv[i], 19200, "none", 7, 1, debug);
HaasAdapter adapter(port, serial, positions);
adapter.startServer();
return 0;
}
The line of code where it points for the error is:
while (aArgv[i][0] == '-' && aArgc > 0)
I really need help getting this program to run ASAP. Thanks guys!
-
September 6th, 2010, 12:18 PM
#2
Re: C++ Newbie, Need Help!
Code:
while (aArgv[i][0] == '-' && aArgc > 0)
aArgc is the count of the elements in aArgv. First you get a element, and then you check if there are actually elements. The process always goes from left to right, so...
Code:
while (aArgc > 0 && aArgv[i][0] == '-')
.. by switching the checks you first check if there are elements, and then use the elements.
Every arrays starts at 0, not at 1.
Last edited by Skizmo; September 6th, 2010 at 12:20 PM.
-
September 6th, 2010, 12:40 PM
#3
Re: C++ Newbie, Need Help!
Thank you, I think that solved the problem. Can't believe I didn't see that
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|