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

>>he wants me to write a system which sends morse code by a serial port
That would be pretty easy to do in either c or c++. Only have to convert each character to a series of dots and dashes then send them.

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

>> I'm more of a visual baic & c# man, and wish my project would let write it in VB or C#
This is c++ board. If you want vb or c# then ask your question there.

>>String copsoutput;
That needs to be lower-case s on string string copsoutput; >>to assignt the output to a varaible would I do something like
Yes -- you got the idea :)

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

Here is another way to do it

#include <iostream>
#include <algorithm>
#include <ctime>
using namespace std;

int main()
{

    const int maxnum = 10;
    int nums[maxnum] = {0};
    srand((unsigned int)time(0));
    int curnum = 0;
    for(int i = 0; i < maxnum; ++i)
    {
        bool found = false;
        do
        {
            int x = rand() % 50;
            int* result = std::find(&nums[0], &nums[maxnum-1], x);
            if( *result < 0)
            {
                nums[curnum++] = x;
                found = true;
            }
        } while( found == false);
   }
    for(int i = 0; i < maxnum; ++i)
        cout << nums[i] << "\n";

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

If you are wanting to contain an array of unique random numbers, then

for each element in the array
    generate a random number
    search the array to see if the number already exists
    if not, then add it to the array
    otherwise, if it was found then go back and generate another number
end of loop

// something like this

const int maxnums= 10;
int nums[maxnums] = {0};
int curnum = 0;
for(int i = 0; i < maxnums; ++i)
{
    bool found = false;
    do {
       int  x = rand();
       for(int j = 0; j < curnum && found == false; ++j)
       {
            if( nums[j] == x)
            {
                found = true;
            }
         }
        if(found == false)
       {
            nums[curnum++] = x;
       }
    } while(found == true);
}
Run.[it] commented: Thank-you +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ compilers also compile pure C code -- its like getting two compilers for the price of one (which in this case is zero). :)

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

But Why this works !!!!!

That works because function foo() is not attemptig to modify a pointer that was declared in main(). It's perfectly acceptable for a function to return a pointer like it did in the code you posted.

Alibeg commented: He answers everything...right. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Does anyone do that any more? I thought they were made obsolete by the cell phone and satrllites.

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

when you click agree , its the same as signing a contract. You are legally bound by what you select.

I'm not so sure about that -- how do they know who clicked on it? At most all they can tell is the ip address of the computer that was used, and in some cases they can't even tell that (for instance the computer I use doesn't expose the actual ip address to the internet). Or they might get my user name and email, that those could be lies too.

It might be interesting to see if there were any legal decisions (i.e. court cases).

When I sign a contract there have to be witnesses to see that I am who I say I am. That isn't the case when clicking an Agree button. My three-year-old grandson could have clicked it as far as they know.

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

line 27: That whole function is screwy. When line 27 is executed it will stop that loop because the function will end. The code you put there is not what that function should be doing at all. It's supposed to search though the array and erase the item that contains the same name as the function's parameter. You have to use a loop (like you have already written) and inside that loop compare the array with name

// this may not be exactly right because I don't know the class structure
if( array[i] == name)
{
    // found it, so now add code here
     // to remove name from the array
}

Most (if not all) the other methods where you did NOT say you need help are also incorrect.


You didn't post the header file that contains the class declaration, so can't really help much.

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

My only question is why create a
MyParam*p
instead of a MyParam p ?

Because void* is a pointer and you can not case a pointer to a non-pointer. Pointers can only be case to other pointers.

but could you have cast to a MyParam and used . instead?)

Yes, but its more complicated (and looks ugly too) than just using the ->. And you have to do that every time you want to use it. cout << (*p).myvector1[i] << "\n";

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

You might also check out boost libraries string tokenization. I've never used it, but looks promising for your program.

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

>>This is fetched in the Pro*C code
Pro*C is a compiler, not a language. So you can use any C compiler you want.

Don't expect a quick solution to your problem because there isn't one. Here is one example of parsing html code. You just have to search though each line of the html file and insert whatever you want. There is no magic way to do it.

>>So how do i traverse each record? Getting

std::string line
ifstream in("filename.htm");
ofstream out("newfile.htm");
while( getline(in, line) )
{
    // search and replace text here
    //
    // now rewrite the line
    out << line << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are many classes which must be link or in other words put together in order to work as one big class.

Oh, do you mean inheritence?

class base
{
   // blabla
};

class derived : public base
{
    // linked (derived) class
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its just a normal text file, so just use standard stream io on it. Other than that advise its impossible for anyone to tell you more from what little you write. Sort of like walking into an auto repair ship and saying "My car doesn't work can you tell me how to fix it?".

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

why not just put an int there, and you can juse use RECT instead of initRecArea

unsigned int cnt;

	for (next=45, cnt=48;next<=255;next+=30, cnt++)	{
		OnCreate(hwnd,cs,RECT(205,45,55,20),(HMENU)cnt);
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its working for me this morning, don't know why.

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

That's just another silly conspiracy theory. Don't believe it.

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

moved because this isn't a VB.NET question.

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

Use code=cpp .

That doesn't work. Needs to be [code=cplusplus]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
struct MyParam_t {
  vector<double> *myvector1;
  vector<double> *myvector2;
};

Don't do that ^^^^ -- make the struct like you originally thought, see below.

struct MyParam {
  vector<double> myvector1;
  vector<double> myvector2;
};

void fn(void *ptr)
{
    MyParam*p = static_cast<MyParam*>(ptr);
    for(size_t i = 0; i < p->myvector1.size(); i++)
        cout << p->myvector1[i] << "\n";
}


int main(int argc, char* argv[])
{
    vector<double> d;
    d.push_back(1.0);
    d.push_back(2.345);
    MyParam p;
    p.myvector1 = d;
    fn(&d);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If its already in std::string then use stringstream

#include <sstream>
...
...
char Comma;
std::string LineDummy;
std::string text;
int one = 0;
int two = 0;
std::string MainLine = "Hello,1,2";
stringstream str(MainLine);
getline(str,text,',');
str >> one >> Comma >> two;
cout << text << "  " << one << "  " << two << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Try posting one in this thread in a reply.

Test to see if it works in a reply

Result of test: doesn't work.

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

I would imagine that would depend on the operating system. Under MS-Windows programs can hog all the memory it wants (16-bit programs are restricted to 640K). AFAIK there is no way to restrict usage by a given program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
for(i=0; i<M && !fp1.eof(); i++)    
          {
               	for(j=0;j<N !fp1.eof();j++)
                {
                  	fscanf(fp1," %f", &a[i][j]);
                }
          }

or something like this

i= 0;
j = 0;
while( fscanf(fp1," %f", &a[i][j]) > 0)
{
     j++;
     if( j == N)
     {
          j=  0;
          i++;
      }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using cout then you can use setw()

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

int main(int argc, char* argv[])
{
    cout << setw(10) << "Hello";
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13 is wrong. You are passing a pointer to a pointer as the second parameter. Leave off the & symbol ReadFile(hFile, someread, sizeof(someread), &n, 0); Also the program should check to see that CreateFile() succeeded. Never assume success.

If myfile.txt is a standard ascii text file with lots of lines then you would be better off reading it with FILE and associated functions instead of ReadFile().

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

see this article. You should bookmark that site because it has a wealth of MFC code that you can freely use.

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

I'm using IE7 on Vista too. I made several posts this morning without a problem, but experienced it again when a post contained a link. Possibly its the links that causes it problems ?

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

maybe you should read a tutorial

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

Ok Then Ill try other function.

Yes i am using Turbo C..

Stop using that compiler. There are several free compilers you can get that work with long file names.

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

put the numbers in an array

int array[3] = {3,1,5};
int largest = array[0];
int smallest = array[0];
for(int i = 1; i < 3; i++)
{
    if( array[i] > largest)
        largest = array[i];
    // now do similar for smallest
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't recall seeing that problem, just the one I reported. Maybe the two are related ????

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

I still can not upload them.

Upload of file failed.

The zip file is only 682K.

[edit]Thinking it might be too big, I deleted some stuff and reduced the zip size to 7K. upload still fails.[/edit]

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

If it worked in Turbo C it was because you were lucky. header is an unallocated pointer. Since it is in global space the pointer's value is initialized to 0 during the program's startup code, which is executed before main() is called.

The program crashes because you need to call malloc() to allocate memory to that pointer before calling fread()

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

Yes, I already told you how to do it 7 hours ago. use _chdir() function to change the working directory. There are several functions you can use to spawn another executable program. system() is one of them, CreateProcess() is another on MS-Windows operating system.

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

I wrote this intending it to be either able to swap a structure, or just the data defined within a structure.

Will the swap function be able to do this, because.. when i tested it, it seemed to fail. but i didnt except it too.

It fails because all it does is swap the pointers within the swap() function itself because the pointers are passed by value, not by reference.

void swap(void** a, void** b)
{
    void* temp = *a;
     *a = *b;
      *b = temp;
}

Now the above will work ONLY if you pass a pointer to a pointer. It will also fail if you pass a pointer to some object.

int main()
{
    int a = 1;
    int b = 2;
    swap(&a, &b); // <<<<<<< wrong

    int* c = &a;
    int* d = &b;
    swap(&c, &d); // <<< OK
// when the swap returns, pointer c will point to b and pointer d will point to a.
// The value of [b]a[/b] and [b]b[/b] are still the same, only the two pointers
// were swapped

it should atleast work for swapping the data stored within the structure though, shouldnt it?

No.

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

BTW is there any tutortial about system("")? like i want to change dir open files using system("")

Probably not -- it is just too simple a function for any tutorial. All you can use it for is things that can be done in a command prompt window. You can NOT use it to change a directory in a C or C++ program.

The chdir() function only affects the working directory of the current process.

The system() function creates a new process in order to execute the command.

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

I still don't know exactly what you mean. Are you talking about the order in which a program executes the lines, for instance

char* a = new char[25];
// something here
char* b = new char[25];
// more stuff here

Or are you asking if the memory allocated to b above is adjacent to the memory allocated to a. Don't get bogged down in all the nitty-gritty details because that will be compiler and operating system dependent. There are lots of different kinds of memory allocation schemes, even within the same operating system. MS-Windows has a least seven different schemes. I don't know how many schemes *nix has.

>>How does the default new operator handle classes vs. structures?
They are handled the same. In c++ the ONLY difference between a class and a structure is the default access type. structures default access is public while classes is private. Otherewise they are exactly the same.

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

>>Could it be compatability issue btn Vista and Visual 6.0
Yes. Toss that compiler out and upgrade to VC++ 2008. The Express edition is free, but doesn't support MFC.

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

does abc.exe exist in that directory? And do you have execute permission there?

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

which is hardly surprising. Those people created the church which, being created, concluded that creationism is valid.
And that church now teaches creationism to those people, who created that church to be always correct.

Darwin created the theory of evolution, which today is still just a theory, but I'll admit that it is a pretty darned good one too. No one will every know which if either is correct because there is no way to trace the evolution of man back to the origins of the earth. Nor can anyone prove the creationist theory.

Its all just speculation.

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

One of the computers on my lan is named Victor. This works

system("dir \\\\Victor\\SharedDocs");

So I suppose you could do this

system("\\\\192.168.23.5\\c\\abc.exe");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think this has raised its ugly head again. Every time (well most of the time anyway) I post in a thread I get this error:

The following errors occurred when this message was submitted

But if I hit the IE7's Refresh button my post was acaully made.

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

OMG am I happy that I use Microsoft Visual Studio. All that makefile stuff makes my head swim. :)

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

>>wat i wanted is that it if the row binary wif the bits
Stop writing like this is some chat room. It isn't. Spell out the words.

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

HI guys.
Im a student and studying c++ that and cmd and so far i stil havent figure out how to change my current dir while my program is running.

See _chdir() function

My program is that i want to make a test.txt file with a "my test file" inside it , in the drive c: directory

#include<stdio.h>
#include<stdlib.h>
void changedir()
{
//system("cd c:");  doesnt change my dir
//system("c: ");     doesnt change my dir


}
void main(){


//changedir();                                     //change dir that doesnt work.

system("echo my test file > test.txt");       //writes my test file inside the test.txt file.

//getche();
}

don't use the system() function for that. Just open a stream object and write to it.

FILE* fp = fopen("test.txt","w");
fprintf(fp,"my test file\n");
fclose(fp);

Your program does not have to be in the same directory where that file is located. You can also specify the full path to the file

FILE* fp = fopen("c:\\some directory\\test.txt","w");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

system("\"D:\\Program Files\\Internet Explorer\\iexplore.exe\" 192.168.23.5");

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

If that function is called recursively then you can't open the file for output on every recursive iteration. Open the output file before calling that function the first time and pass it the file stream

void Arbol::updateFile()
{
Nodeptr p = miArbol; // myTree
ofstream fout("filename");
Recorrer(p, fout);
fout.close();
cout << "File updated!" << endl;
cout << endl;
}    

void Arbol::Recorrer(Nodeptr p, ofstream& fout) 
{ // Recorrer began
 
if (p != NULL)
 { // if began
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This is a code wich proves this point
Your code proves nothing.

>>the pointers in the class should occupy memory in the order they are declared
Don't count on it. 1) never use malloc in c++. 2) whether malloc or new is used there is no guarentee how the memory will be allocated. Might be consecutive, and might not. Lets say you have three pointers, a, b and c delete a and reallocate it with a larger amount of memory. Will it use the old memory location (no because its not big enough). Will it follow the memory allocated for c ? Probably not especially if some other pointer d was previouslly allocated and then deleted.

When I said it would be allocated consecutively I meant this:

class MyClass
{
   // blabla
};

int main()
{
    MyClass a;
    MyClass b;
}

In the above the memory for MyClass b will probably immediately follow MyClass a. But again you can't count on it because it will be implementation dependent (the compiler is free to allocate memory any way it wishes.)

Another argument against it is what happens when you have two processes that allocate memory. Process A aloocates a pointer, then process B allocates a pointer, then process A allocates another pointer. The memory locations allocated by process A may or may not be consecutive because process B allocated memory between the two pointers in process A.