DeanMSands3 69 Junior Poster

...at what point do you start to learn the more advanced stuff?

When your professor's first spoken language is not the same as your own. That's when you get into the crazy stuff.

DeanMSands3 69 Junior Poster

Either use a return value or a pass-by-reference parameter.

//Using a return value
int getLength(char *myString){
    int length;
    for(length=0;myString[length]!=0;length++){}
    return length;
}
//Passing by reference
void getLength(char *myString, int &length){ //notice the '&' before length
    for(length=0;myString[length]!=0;length++){}
}
DeanMSands3 69 Junior Poster

I was going to roll my own, but this works just fine.
http://www.fredosaurus.com/notes-cpp/algorithms/string2int-ans.html

Adapt it to eliminate the bools if you need to, but the code should work just fine.

DeanMSands3 69 Junior Poster

Are you running Windows, Mac, or Linux?

If Windows, are you using Visual Studio, NetBeans, Eclipse, Dev-C++ or Turbo C++?

DeanMSands3 69 Junior Poster

There are two loops in the bubble sort. With one loop, essentially, you're only doing one pass, sorting the highest value to the top, but neglecting the others.
This may prove useful: http://www.codecodex.com/wiki/Bubble_sort


Also, you may want to change that i==5 to i==4. When i equals 5, you'll be starting your second line, but you're putting in the line break after you've printed arr[5]. Since you 10-element array goes from 0...9, you'll be printing something like
0 1 2 3 4 5
6 7 8 9

Hope this was helpful.

Happy coding!

DeanMSands3 69 Junior Poster

The disagreement is minimal. Having done low-level code, I often think in low-level. But the user will likely never notice. Ever.
As deceptikon said:

There's not going to be a significant enough difference for you to worry about it.

One thing I neglected and he's right about is that, yes, using const chars are easier to debug than macros.

DeanMSands3 69 Junior Poster

#1 and #2 are, at run time, essentially the same except that enums (if I remember correctly are integers instead of characters). Also, they will be doing stores and comparisons with literal values (i.e. x=1,y>2, z<3) instead of referenced numbers.

#3 will use more memory at run-time since it allocates the const chars then references them (i.e. comparing by reference).
At the CPU level, this makes a world of difference. Since the CPU has to access the memory to get the number you're referencing, it will take more time to process it as opposed to you simply handing it the number.

DeanMSands3 69 Junior Poster

Two possibilities.
A. roll=int(num*11)+2; //Just reduce the 12 to 11 and add 2 instead of 1.
B. rewrite it to roll a single die, save the value, then roll again.

DeanMSands3 69 Junior Poster

Yeah... that's happened to me. My church was using a free web host and wanted to create a mailer. Much to our surprise....
I've since moved to paid hosting and that's no-longer a problem. But for you, that's not really an option I guess. Sorry to hear it.

DeanMSands3 69 Junior Poster

Is your blat program in the system path or where your program can find it?

DeanMSands3 69 Junior Poster

Let me explain the system("...") function.
system("x 1 2 3"); calls a program "x" and passes it the parameters 1, 2, and 3.
So instead of dropping system() entirely, you'd be doing something like system("blat blah.txt -to somebody@somewhere.com");

Also note that blat requires a text file to email, otherwise it might not work.
Also, there's a really good chance your email server will mark your file as SPAM. Make sure to check your spam folders regularly. But who knows?

DeanMSands3 69 Junior Poster

string is a C++ type. You'll want to convert your code to use C++ instead. string.h is a C header file and doesn't provide that.
If you don't want to use C++, you should use character arrays. And instead of acountry[j]=arr; you would use strcpy(&acountry[j].code,&arr);

DeanMSands3 69 Junior Poster

Well, for starters, you want to put your code inside the [ CODE ] blocks. It preserves the formatting.
Looking at your code isn't as much fun without indentation.

And... and... you have used GOTO. And you have sinned.

Just kidding. (But you may want to look into ways around that.)

I would break the code down into functions to make it more modular and also easier (MUCH EASIER) to read.

Before we go any farther, I will give you an out. Everything you want to do CAN be done using cout and cin and the dec, oct, & hex modifiers. And also scanf with
the x modifier will work.

Now, to get you started, I want you to look at this:

a[i]=a[i]-48;

That works for numbers. And only numbers. If you want to add hexadecimal, you need to look beyond numbers.
Try this.

if(a[i]>='0'&&a[i]<='9'){	//Only use this conversion for numbers
			   a[i]=a[i]-48;
		   }else if(a[i]>='A'&&a[i]<='F'){	//Only use for upper case letters
			   a[i]=a[i]-64;
		   }else if(a[i]>='a'&&a[i]<='f'){	//Only use for upper case letters
			   a[i]=a[i]-96;
		   }

More to follow.

DeanMSands3 69 Junior Poster

Why did I say that? The way you worded your question gave me a clue you might be a little green. A semi-seasoned coder would have asked for help in socket programming. They might have even mentioned watching "sendmail" programs inside a WireShark session.
You didn't word yours that way. Instead, you asked for a finished product without realizing it.
Now to business. Your proposed method system("mailx...") calls an outside program (mailx) to send the email. Admittedly, that's a simpler solution I hadn't considered.
Now, mailx is a Unix/Linux program. You can get a Windows version, but it will insist on some Unix-isms you may not be happy with.
I recommend having a look at blat or any other open source email program designed for Windows.
Look over the command-line usage and adjust your system("..."); command accordingly.

Happy coding!

DeanMSands3 69 Junior Poster

What you want to do is likely above your present ability. (For now.)
I'm telling you this kindly.
However, you have asked a question, and I will answer it.
(Who knows, this might be the start of a wonderful new world of socket programming for you.)

First, since you are using Windows, you will want to familiarize yourself with Winsock.
Google windows socket tutorials
You will find a nice tutorial for it here:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9818&lngWId=3
And a handy reference here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms738545(v=vs.85).aspx

Code Project is also a fantastic place for finding code examples, but you'll need to register to download.

Since you are using the MinGW compiler (part of Dev-C++), you will need to add -lwsock32 and -lws2_32 in your libraries.

Once you're comfortable with writing socket code, I suggest you have a look at this:
http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol
Have a look at the example exchange in the article. It'll help.

Happy coding!

DeanMSands3 69 Junior Poster

These is not the article you are looking for. (Especially Method 3.)
http://www.codeguru.com/cpp/i-n/network/networkinformation/article.php/c5451

DeanMSands3 69 Junior Poster

File->New Project->Static Library.
It will create an .a file.
Reference that project in your linker libraries in your next project.

DeanMSands3 69 Junior Poster

Well, this goes back to 16-bit addressing (as revealed by your use of near).
In 16 bits, the size of an int (being 16 bits) is 2 bytes.
You increment it twice. But the compiler knows it's an int pointer, so it increments it by 2 each time.
So you're adding 4 to a value already holding 0xFFFF. Adding 1 to 0xFFFF in 16 bits rolls over to zero. What do you figure you have left?

DeanMSands3 69 Junior Poster

Well, look at what's happening to your pointer and it'll let you know.
I modified your code to do this.

#include<stdio.h>
#include<conio.h>

void main()
{
 int arr[3]={2,3,4};
 char *p;
 //clrscr();
 p=arr;
 printf("*p:%d, p: %ld\n",*p, p);
 p=(char*)((int*)(p));
 printf("*p:%d, p: %ld\n",*p, p);
 p=(int*)(p+1);
 printf("*p:%d, p: %ld\n",*p, p);
 //getch();
}

It gave me this.

*p:2, p: 2293552
*p:2, p: 2293552
*p:0, p: 2293553

Let's take it one step further.

#include<stdio.h>
#include<conio.h>

void main()
{
 int arr[3]={2,3,4};
 char *p;
 //Int size is 4 on 32-bit so cast arr as char* before adding.
 char *end=((char*)arr)+sizeof(arr);  for(p=(char*)arr;p<end;p++){
  printf("*p:%d, p: %ld\n",*p, p);
 }
 //getch();
}

Which, on a little-endian 32-bit system yields:

*p:2, p: 2293548
*p:0, p: 2293549
*p:0, p: 2293550
*p:0, p: 2293551
*p:3, p: 2293552
*p:0, p: 2293553
*p:0, p: 2293554
*p:0, p: 2293555
*p:4, p: 2293556
*p:0, p: 2293557
*p:0, p: 2293558
*p:0, p: 2293559

(Notice that the pointer shifted from 2293552 to 2293548. This is unimportant except to know that there are differences between the two programs.)

Hopefully, this is clear as mud and just as tasty.

Happy coding!

DeanMSands3 69 Junior Poster

This maybe useful to help you understand:
http://en.wikipedia.org/wiki/MSDOS#Legacy_compatibility
http://en.wikipedia.org/wiki/Microsoft_Windows#History
http://en.wikipedia.org/wiki/16-bit_application
http://en.wikipedia.org/wiki/32-bit_application
http://en.wikipedia.org/wiki/64-bit_application

As you can see, Windows follows two family trees. The upper left tree is based on MSDOS, which is a 16-bit operating system. It required special software to allow programs to run in 32 Protected Mode. Windows 95, 98 and ME were built on top of MSDOS. They use 32-bit mode on top of 16-bit "Real Mode." Programs written for MSDOS will run on Windows 95, 98 and ME with few problems.

Now we come to present day. Windows XP is built on the Windows NT kernel. NT was built 32-bit from the ground up. It has nothing to do with MSDOS. It has to use a special emulation mode to allow MSDOS programs to run on it. And often, those programs don't work the way they should. That's why a group of people got together and wrote the program "DOSBox" and other MSDOS emulators.
With 64-bit OSes, support for 16-bit software is often dropped entirely. You will need to run those programs inside emulators.

Turbo C writes software for MSDOS. Those programs may or not run correctly in Windows. They might.

Visual C++ (newer versions) will generate software for Windows.
Other recent compilers will too (generally speaking). MinGW (based on GCC) is a popular free compiler that comes bundled with Code::Blocks.
It can also be used with NetBeans or Eclipse.

DeanMSands3 69 Junior Poster

Look at this function from the site I mentioned earlier. I did some debugging and the mouse coordinates start way out in never never land even though the cursor is clearly visible on the screen. Restrict the mouse coordinates to the display min and max and you're good. Look into getmaxx() and getmaxy() on getting those.

void restrict (int x1,int y1,int x2, int y2)
{
	in.x.ax = 7;
	in.x.cx = x1;
	in.x.dx = x2;
	int86 (0X33,&in,&out);
	in.x.ax = 8;
	in.x.cx = y1;
	in.x.dx = y2;
	int86 (0X33,&in,&out);
}
DeanMSands3 69 Junior Poster

Gourav1, you are now my new favorite poster. You give us problems from 15 years ago. To check and debug your code, we'd need DOSBox and an ancient (and completely legitimately obtained) copy of Turbo C++ 4.5. Epic win.

http://www.go4expert.com/forums/showthread.php?t=21153

Have a look at this page. Run all the examples. And see what works.
I'm wondering if perhaps your mouse coordinates are outside the drawing range of the screen. Who knows?

DeanMSands3 69 Junior Poster

How many copies of MinGW do you have on your system? If you're using Dev C++, then that makes at least one.
Reference: http://cboard.cprogramming.com/cplusplus-programming/111216-compiler-problem.html

Make sure to use a recent copy of MinGW and update often. I would also include a bare-minimum MSYS including Make.

DeanMSands3 69 Junior Poster

Threads can return values.

Which API are you using?
Here's an example for PThreads:
https://computing.llnl.gov/tutorials/pthreads/#Joining
Since the thread function is a void pointer, it can point to any piece of data you like, and is retrievable with the pthread_join function.

For Windows, you can use the GetExitCodeThread function.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683190(v=vs.85).aspx

vedro-compota commented: +++++++++ +3
DeanMSands3 69 Junior Poster

I haven't gotten into CLR C++ yet, but I'll take my best shot.

MyDataType_Class ^myFunction(String someName="",int someID=0){
    MyDataType_Class ^new Person=gcnew MyDataType_Class();
    Person->id=someID * 2; //Multiply by 2 just because
    Person->name=someName;
    return Person;
}

.
.
.


void SomeOtherFunction(){
    MyDataType_Class ^thisPerson=myFunction("Runcible Spoon", 21);
.
.
.
}