jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put it in a file named something like "ParseBBCode.h". Include that header in your Form1.h file (or put it in stdafx.h, but that's not necessary). You do not need to include <string>, the String ^ in this case is a System::String^ from .NET.

You will either need to put a using namespace System; at the top of your header (not a good idea, as everything that includes it will now have that namespace) or qualify your String^s in the header as such:

System::String ^ ParseBBCode(System::String^ OriginalText);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm assuming that you're working in C++/CLI since you are doing WinForms. Check out the BackgroundWorker, as I believe that's the most straightforward way of getting a separate thread (and I believe it was designed for exactly this purpose, i.e. for separating the GUI and the meat of the code).

Just make sure you're not running life support systems or nuclear missile silos with these motors. If that's the case, you'd probably want something embedded.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i can just include a welcome speech at the end of my post.

Put it in your signature. "If you're new, welcome, if you're returning, welcome back, and if you're here all the time, you're WaltP" :)

jingda commented: Nice one +0
WaltP commented: Ouch, my side hurts :-P +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make a list for yourself of precisely what is confusing about those topics, for example

Typecasting:  Is it necessary to cast my variable when I am doing XYZ
Twos compliment:  How do I handle negative numbers

etc.
Now you have a list of things you can search other sites for, like you can Google "C++ typecasting XYZ" or "2's compliment negative numbers". I know people on this site would be more than happy to help you with specific questions about specific areas, but you've got to figure out what those are.

Fbody commented: Very true, And good advice.. +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

index <= 5 Your array is only 5 elements long, you should go up to <5 only (0,1,2,3,4)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks.

Otherwise, he will have to play a little game of #defining and #undefining the keyword around every use of it.

Yes, that would be painful.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Anyways, if you really have to use it, you can undefine the define after including the other library.

I had thought about that too, but what if some of the functions in the code depend on that symbol? Does it not matter by that point?

(sorry @OP to inject a couple of my own questions here, but since we're talking about it...)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sure, make me open the darn program. Just kidding.

This is what I was trying to remember in the last post:

Go to Project
<Your Projname>Properties
Configuration Properties
Linker
General
Additional Library Directories -- add them in (where are the lib files? - can be more than one directory

Then, still under Linker

Input
Additional Dependencies -- add in "mylibrary.lib, mylibrary2.lib"

I'm assuming you already put in your include directories under

Configuration Properties
C/C++
General
Additional Include Directories.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's a linker error, actually. Have you pointed VC++ to the right library directory and listed out the .lib files you want it to link to? (all this under Project/Properties/CC++/Linker (inputs and general)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure if this will work, but try referring to the global one as ::thread and the Boost one as Boost::thread .

Edit: no, the more I think of it, the even less I think that will do it because the global one is a define, you're not really calling it anywhere. Sorry, wish I could have been more help. I was thinking about reordering the header files, but I think that might only be a patch fix. Doubtless you probably googled about combining this library with boost, but someone has to have encountered this before.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does your question have to do with the subject of the thread?

Have you tried searching on Google? There are at least a few pages particular to C++ flowcharts, but as far as I can remember, the process is pretty much language agnostic.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One way would be to go through the string and replace the ':' with a ' ' (either in a for loop, or through something like the .replace() method of the string.

Edit: Vijayan has a good way ^^^^^^^^^ (I was thinking along those lines but was trying other rhings, oh well).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If N=9 in your prior example, each pass you'd be writing into bd[9][9], right? Well, the array only goes up to bd[8][8]. When you declare an array, you give it's dimensions, but when you're accessing the elements you have to start numbering at 0.

In your loop, to access the (ith,jth) element, just use bd[j], which will work for input and when you're printing the values out. So within your for loops:

insert >> bd[i][j];
cout<<bd[i][j];  //add in your own spaces and newlines for formatting purposes
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do your API call in a backgroundworker (http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx). It's the "easiest" way to do threading in .NET. The only thing is, you have to pass back your information to the GUI in a specific way (which I cannot remember right now).

triumphost commented: Thanks for all your help :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The StringF in Form1_Load() is a local variable, which masks the "global" (really it's a member of the Form1 class) variable. Remove the System::String ^ portion off of the one in Form1_Load and it should be all set.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do you know it's not working, you didn't print out anything!

With the extraction operator >> you don't need to read in the whole line, as if that were the case, you'd have to parse out all of the integers. Get rid of lines 16-22, you'd only need those if you were reading in line by line, but since you know how many elements there are, the for loop is taking care of it for you. You don't need to redeclare bd, as it's being passed in from whatever parent function you are calling this function from.

Keep 24-29, but it needs some changes. Your array is 3x3, correct? Check your loop indexes, trace through the loops on paper and see which elements are being read. No matter what N is, bd[N][N] is not an element of that array anyhow, you're one past the end in both dimensions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Substitute bd[i][j] for a

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

itsRadius is a pointer, you need to dereference it before incrementing it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Eliminate line 19 from your code.

If you use the >> operator, you can read in the numbers to an int variable. Is it guaranteed that your text file will contain NxN numbers. A nested for loop will help you to read them in, and it will look like insert >> (the integer variable).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hmm. Apologies that I'm not quite getting this. Are you trying to write numbers that are in the lines of text into the "bd" array? If so, you have to extract them somehow. What does text.txt look like?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where are you printing out the array?

I'm very confused, because the code you pasted above reads in a line and immediately prints it out. Is that the text to which you are referring or another line of text?

You won't be able to select where the text goes unless you are able to use a console library.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

its at the bottom of the page instead of where the array is

I'm not exactly sure what you mean by that, can you show a sample output?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If You are helping someone with Knowledge and if you think you should limit yourself in offering help, based on that person, then your thinking is slain.

I don't think that's correct. I don't think anyone would argue that we're here as a homework or coding service.

Since any one of us could be in a role of asker or answerer, the prerogative of being "always right" is not suddenly extended to the asker at the expense of the answerer.


I think if an OP starts being abusive, you have every right to sick this guy on them:

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're always going to get some highly motivated people that are truly stuck or wanting to supplement, have made the effort, and are grateful for the help. The other side of that coin isn't always so pleasant. Don't let those bad eggs grind you down.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

calling a native C++ DLL from C# is possible

See this recent thread http://www.daniweb.com/software-development/cpp/threads/355990 for the caveats of that statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

However with all the libraries available for C++, wont C++ still stay a bit head when developing native programs?

Yes, it will stay far ahead. C++/CLI was never meant to home in on the C++ market, but was just meant to be a tool that is right for some jobs.

I'm assuming then using .NET wont allow you to use the a program developed in C++\CLI to compile and run on say a Mac then, compared to a general c++ program that can be compiled and run on a mac ?

Not yet, but maybe not ever, I don't know. I know the mono project (http://www.mono-project.com/Main_Page) is trying to get C# and .NET to work across Windows/Mac/*nix, etc., but I don't know if they have any plans to port C++/CLI. A library like Qt (which has GUI elements, but also has other components for things like sockets and database access), is something that would serve you well in developing cross platform apps.

Sorry if my questions seem a bit naive just trying to cover all my bases

No worries, sometimes it's hard to find information out on the net about it. I think some people want to put it out to pasture. I just find it to be an interesting dialect.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C++/CLI is the dialect of C++ which you use under the CLR. Languages that use the CLI have their code converted to MSIL (which is like assembly language, but not quite the same). The MSIL code gets run on a virtual machine, and a just in time (JIT) compiler turns it into bytecode. (I may have glossed over some points, so Wikipedia has great info on all of this for further reading).

When MS created managed C++ (the precursor to C++/CLI) they intended it as a go between in the relationship of native C++ and C#. That is its biggest advantage, IMO. You can write code in C++/CLI, and call it directly from C# (or VB, etc.), whereas calling a native C++ DLL from C# is possible, but requires a more elaborate procedure known as a platform invoke (P/Invoke). Of course the C++/CLI approach isn't perfect, and still requires a lot of translating pointers when there's any native code present. One upside is the ability to write WinForms programs in .NET, rather than operating with Win32API directly.

The downsides are numerous. This is not standard C++ by any stretch of the imagination. Some of the syntax is different, managed pointers are known as handles, which behave largely the same, but require some getting used to (as the memory is now managed by a garbage collector since you're in .NET). It's a bit esoteric (that's kind of what I like about it, actually), so it's not necessarily something that's …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since you are within a method of the object (set()) you can assign to the private members of the class directly. Get rid of line 34, and insert

x = p1;
y = p2;

(or just take the values from cin directly into x and y)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, I think you were well within your rights to say that. He didn't offer you any constructive criticism/justification with the downrep, so I wouldn't take it to heart. You contribute a lot to the site, so just let the good reps counterbalance this one.

P.S. The real crime here is that some people still use VB4

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the ifstream as you are doing, it's a more C++ way of doing it than calling fopen is.

gcount() might work to tell you the number of characters you are going to send, as that will tell you how many characters you actually read in. It wouldn't buy you much with the seekg, as you'd have to "unget" all of the characters you just got.

I was suggesting rewind because it takes care of everything for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But there is another problem: I tried to transfer the file using a TCP socket, but the received file seems corrupted

You could have put that in the question, too. lol. No worries. Try changing your second seekg call on line 20 to a rewind http://www.cplusplus.com/reference/clibrary/cstdio/rewind/. That will bring you back to the beginning and reset the error flag (just seeking won't help the fact that the stream is invalid due to reading to the end of the file on the first run).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you had a fixed-sized array, you can use sizeof:

char a[5];
cout<<sizeof(a); //5

but if you were to pass it into a function as a pointer, that information is lost (as the array is reduced to a pointer).

void myfunc(char a[])
{
   cout<<sizeof(a);   //4
}

int main()
{
  char b[5];
  cout<<sizeof(b); //5
  myfunc(b);

}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The sizeof() operator is giving you the size of the pointer named "buffer", which is 32 bits (4 bytes).

Just use bufflen for the size of the buffer in the get() call.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

P.S : I'm a she

Pardon my assumption, then. ;) Glad the code is working now.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He was missing the copy constructor declaration within the class, though.


(4000) - ignore this, just a counter

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

From the errors you were getting, did you try the include guards that thekashyap was telling you about? That would probably take care of the redefinition errors since you're including everything in everything else. Try those first and then I'll try the full project.

EDIT: I added the include guards to each of the headers and added:

VendingMachine(const VendingMachine & vm);

(the declaration of the copy constructor that you had defined in VendingMachine.cpp) and it compiles fine (one warning about unused variable 'a' in main()).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're not opposed to doing so, zip up your project folder and attach it. I feel like I don't have enough to go on with what you have posted. Also, in testing the code I had to substitute in for the Cigarette class etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't see VendingMachine.h/cpp posted, so I don't know how you say that.

Sorry, you are right, I read your response too quickly, I thought you were talking about VendingDisplay.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

don't have only some non-default c'tors

Wha? He does have the default, but in his small example (which may represent only a portion of the actual situation) it's not defined anywhere.

I think that he's trying to pass an object that doesn't match the signature to it when he's instantiating the object in main (and so the error message was one of those "defined from here" compiler messages).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What did main look like where you were trying to instantiate the object?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok i got wxwidgets but have no clue how to install help!!!

I think Dev is going to be one of the larger obstacles to that, as it's outdated. Honestly, I've never conquered that one myself. I know there's a build of it for Windows systems that lags behind the main release by a couple of versions, but I don't remember what it's called.

Can i do this program in java?

Why don't you ask in the Java forum? :) Yes, I'm sure you could, but there is a learning curve to anything. If you know Java and can familiarize yourself with whatever GUI toolkit they are using these days, then sure, but the same holds for C++.

Poke around the net for solutions to installing wxWidgets and if that doesn't pan out, start a thread (here, or in their forum,http://forums.wxwidgets.org/) with a concrete question about installing it (not just "it doesn't work").

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes the characters remain in the stream

Try it with 2 char arrays that you declare one right after the other, which don't have to adjoin in memory but with such a small program they often do, then write more into the second one than it can hold. If you print it out it's clobbered the first one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If someone inputted a string that was 15 letters long, would the leftover characters after the null terminator be discarded? or would they remian in the input stream?

What I was saying in the post above is that in this case, they actually end up clobbering the memory adjacent to the array, so however many characters you have beyond the limit writes over whatever is next to it by that many bytes.

Say we have char arr[4], and there's a second array of size 4 next to it with "abc"
|   |   |   |   |'a'|'b'|'c'|'\0'|
cin >> arr; //we enter "123456"
|'1'|'2'|'3'|'4'|'5'|'6'|'c'|'\0'|
Not only does cin not put the null terminus on (as there's no room), but we've clobbered the other array (as a side effect, any function relying on the position of the null terminus will think this string is "123456c".

And on one last note: is there a way to expand my character array size once it's defined?

i.e. I declare char input[7]. Am I able to, down the road, change [7] to, say, [12]?

Not with a fixed-size array. There's a way to do it (realloc - http://en.wikipedia.org/wiki/Malloc#realloc) if you dynamically allocate the array at runtime with malloc (a C function that is,in some ways, a predecessor to the "new" keyword in C++, but also, I believe, still used in a lot of the underlying machinery of C++ memory management). Look up "new" and "delete" if you want to know how to do things …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i am kind of bossing you guys around

We wouldn't let you actually do that, but thank you for owning up to the issue.

C++ will work. If you opt to go the Visual C++ Express Edition/winforms route, the dialect of C++ used is C++/CLI and has a slightly different syntax, so give that one a second thought if you are thinking about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can someone just give me the code and programs for the program please!!!

Any term papers we can write for you, too? Can I pick up your dry cleaning? ;)

It's at this point that you need to do what rubberman suggested. Find one that you can download for her. I know I'm not going to take you through the minutiae of writing a GUI program step by little step, and judging from the response to your question, no one else is either.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Cout

Int

Cin

Tell me those statements compile on your machine, and I probably won't believe you.

Perhaps you missed the point of my other post. If you don't know which GUI toolkit or system you want to use, then you're not ready to start programming in it.

IMO, it makes life slightly easier in most OO GUI toolkits if you have all of your own code organized into objects. What you have there is not sufficient.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh, no, miscue on my part then. I meant that you can use >> with char arrays. It's conscious of the need for '\0' at the end. You can put in more characters than your buffer will hold EDIT: and it plows through to the adjacent memory. It will only put the '\0' if there's room.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I omitted the cin portion, is that what you mean?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

input[8] is not the last member of your array, input[7] is.

When you declare the array you put the size, when you use the array, you put the index.

After taking in the input, you could say

if(input[7] != '\0')
   input[7] = '\0'

What I think you were doing is trying to march down the string, which you can do by

int i = 0;
while(input[i] != '\0')
{ 
   cout<<input[i]<<" ";
   i++;
}
(it could be a for loop too, I was just using while because you did)
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if you aren't into programming it yourself

I think the OP is into it and has good initiative. I just know from personal experience that jumping into Windows programming can take a lot longer than one originally intended.

@rubberman I think your suggestion of a ready made is a good one. If any of them are open source, that's an even better opportunity for the OP.