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

You have to reset the value of size on each loop iteration

void Registry::enum_key()
{
	int i = 0;
	while( RegEnumKeyEx(hkey , i , name , &size , 0 , 0 , 0 , &filetime) != ERROR_NO_MORE_ITEMS)
	{
		cout << i << ":" << name << endl;
		i++;
		size = sizeof(name);

	}
}
vbx_wx commented: true helper +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>enum_key()

Change that for loop to a while loop. RegEnumKeyEx() will return ERROR_NO_MORE_ITEMS when done.

int i = 0;
while( RegEnumKeyEx( /* blabla */)  != ERROR_NO_MORE_ITEMS )
{

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

Writing binary file would be more efficient, but unreadable with any standard text editor such as Notepad. Note that file_out has to be opened in binary mode.

file_out.write( (char *) atoms, sizeof( atoms));
file_out.write( (char *)&origin_x, sizeof(origin_x));
file_out.write( (char *)&origin_y, sizeof(origin_y));
file_out.write( (char *)&origin_z, sizeof(origin_z));

Then to read it back, just replace write() with read()

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

move lines 9-11 up to between lines 1 and 2. As coded, line 4 can not use cout because it doesn't know what cout is.

Other than that, what is the problem with your program?

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

>>When I do a break point the subjectcode is 84 T. Is the 84 the equivelant to T?

Yes -- look at any ascii chart and see for youself. subjectcode is declared as char, therefore the >> operator will treat is as such. Declare it as an int then test again to see if that fixes the problem. If it doesn't then post a few lines of the data file so we can see what the program is trying to read.

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

>>Does this mean I have an error within the program,
Yes, your program is buggy. Coding and getting a clean compile is only about 25% the job of a programmer. The other 75% if fixing bugs.

>>or could there be an error in the compiling process?

Unlikely. Don't blame the compiler for your buggy program.

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

Use the <map> class to create a list of file extensions and file sizes. As the files are read then update the map. When done just display the map contents. boost will not do that for you, you have to code it yourself.

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

Very few, if any, members here know what those SDL functions are. Is that a library of some kind? If it is, post the link to it.

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

Call srand(time(NULL)) only once during the lifetime of your program. I normally put it near the beginning of main().

You don't replace m_QNo with 300 everywhere in your program. Only in that one function with rand().

I have no idea what that _SCL_SECURE_VALIDATE_RANG macro does.

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

So just add the full path to the filename.

str = "C:\\user\\user\\Desktop\\history\\" + str;
str += ".txt";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My problem is not random no generation.

Yes it is. Try it out and you will see why the generator is wrong.

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

>>i = rand() % m_QNo;

You want to use 300 there, not m_QNo.

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

>> printf("endl");

Huh?? endl is c++, not c, and its not in quotes. I think what you want is printf("\n");

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

Ok -- so what is your question? If this is on your final exam then that means you are at the end of your course. At that point you should already know how to read a file into arrays.

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

AFAIK you can not delete attachments. I have wanted to do the same thing but was told that I can't.

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

Don't you mean you need to use std::string's find() method? e.g.

std::string word = "Hello";
size_t pos = word.find('.', 0);

In the above, just put it in a loop and replace the second parameter to find() with the variable pos that was returned by the previous find. Keep doing that until find returns string::npos.

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

In Intel based 32-bit programs the .data and .bss are really in the same segment. In fact, 32-bit (and 64-bit) programs do not use segments at all. Everything, including both code and data, are in the same segment because the compilers use the flat memory model. Compilers for other processors may or may not do it differently.

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

The questions depend on the platform. Here is a wiki article

The return value on Intel based computers is normally stored in the eax register then after the function returns the value is copied to some variable.

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

If the compiler will generate the proper machine codes and the linker will produce the proper addresses then yes it will produce executable code....The only remaining obstacle is wrapping the executable code in a format recognized by the operating system...

Isn't that the job of the linker?

The program doesn't have to be compiled on the target operating system. There are cross-compilers which run on one os but compiles and links code for another os. I know of at least one os where there are no C compilers available, so the programmer's only choice is to write assembly code.

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

>>When and why we need to use fflush exactly?
Depends on the operating system. When writing to the screen (MS-Windows) I never use fflush() because MS-Windows seems to write immediately. I have seen the problem on *nix computers where it was necessary even after putting '\n' in the output stream.

When to do it? You won't have to put it after every printf() statement, you can delay callinf fflush() until after all printf() statements but before any input statements. Lets say you want to display a menu that has 10 printf() statements. Just put the fflush() after the last printf().

For disk file streams call fflush() after all writing has been done. Its not necessary to call fflush() before the file is closed because fclose() will do that anyway.

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

>>if ( bad = true )

You need to use the boolean operator == instead of the assignment operator =. That is a common error made by people coming from other languages such as VB which use = to be either assignment of boolean.

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

You have to write the code that iterates through all the files in the folder and sum up their sizes. boost library doesn't do that for you. I could easily write such a program without boost, but I doubt that is what you want. You need to write a function that iterates through all the files and directories, then when a directory is found call that function recursively to process all the files in the sub-directory. I posted a code snippet a couple years or so ago that does just that using win32 api functions.

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

you put it in the wrong place. Check the file size on line 39 (inside the else statement). It would make your program a lot easier to follow if you wrote another function to return the file size.

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

You need to stop the second loop after the first printf()

for (d=2;d<b;d++)
    {
        f=c%d;
        if ( f == 0)
            break;
        if (d>=a && d<=b)
        {
            printf ("%d ",c);
            break;
        }
    }
Xufyan commented: thanks :) -> xufyan +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

are you trying to print all the odd numbers between two values? Your program is doing much too much work! It only needs one loop, not two. Delete that second loop and just test if the loop counter d is even or odd.

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

>>player1score = add10 (player1score);

The first example doesn't work because it never changes the value of player1score variable. In the above code, when add10() returns it assigns the return value to player1score. That is not done in the first example. Passing a variable by reference does not do anything if the function does not change its value. Modify the first example like this and you will see the difference

int add10 (int &score) // function that adds 10 to player1score variable by reference
{
      score += 10;
      return score;
}
nats01282 commented: excellent answed my question first post +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanx for the reply.

Tho I'm not sure I understand...

I can list all the files in a directory. Or get a specific file size if i give it a specific file in a directory. So can't I just loop thru the directory and print out the size everytime it finds a file?

.

You mean you don't know how to put the two together so that you can get the size of all the files in a directory? Odd.:-O

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

Why are you multiplying nrows * sizeof(int*)? AnsiStriong is not an int pointer, so that doesn't make any sense.

>>AnsiString **array = new AnsiString*[nrows * sizeof (int*)];

^^^ Wrong AnsiString **array = new AnsiString*[nrows]; >>array= new AnsiString[ncolumns * sizeof(int)];

^^^ Wrong array[i]= new AnsiString[ncolumns];

Salem commented: Nice +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call win32 api function CreateProcess() and you will have a lot more control over how the new process is created. Never tried it with a *.py program.

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

You can not call malloc() to allocate c++ classes. It doesn't work. Use the c++ new operator. You have to call either delete or delete[] to destroy it.

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

You have to iterate through all the files in the folder and sum them up. See the link I gave you earlier because boost has a function to do that.

[edit]^^^ beat me to it :)

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

Here is a good example of why threads should NOT be closed, and resurrection can be helpful to everyone. But this is an exception because most dead threads are not worth resurrecting.

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

Did you see this example?

I see boost::filesystem has at least one redeeming value -- a platform independent way to get a list of all the files and directories.

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

I don't use boost -- just as easy to use fstream which is standard on all (or most) platforms that have file systems and c++. I see no point in using boost to replace fstream.

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

The way I understand the problem, the array does not have to have 10000 elements -- 10000 is just the maximum value that any one element may contain. In otherwords you have to generate an array that contains N elements (allocate with new operator), the value of each element is randomly selected between 0 and 10000.

After you find out the value of N, allocate an array of N integers then populate it with values between 0 and 10000. You can use array[i] = rand() % 10000; in a loop.

After that, you need another loop from 0 to Q. In that loop you need to generate another random number between 0 and 10000 then try to find that number in the array.

Of course, I could be all wrong about the problem too :)

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

>>int abc(void);

That is called a function prototype, which is used to forward declare the function so that the compiler knows what it is, it's return value, and its parameters.

Function prototypes are unnecessary if the function actually appears before it is used, as in the example I posted. You may code the prototype, but it is not required in that case.

The code you posted does not compile because you did not code the function prototype correctly. Change it to this: int abc(float *b); Now change the actual function like this:

int abc(float *x)
{
float p;
scanf ("%f",x); // NO & symbol here because x is already a pointer
// Here is another way to code it
// maybe it makes more sense to you
// what it is doing.
p = *x;
return p * p;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Seek to the end of the file and call tellg(), or whatever function boost used to return the current file position.

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

line 14: That declares an array of MAXSTRLEN number of pointers. Its not a character array. Remove the *.

line 21: There is no need for the typecast.

line 22: There is no need to increment both variables i and count because they both have the same value.

line 24: make sure to null terminate the string.

lines 28-31: Why print the string one character at a time? Waste of good cpu time and bandwidth. Just print it all in one shot printf("%s\n", str); lines 34-38. That does nothing. No conversion is needed to display either character value or decimal value.

line 48-52: That could be done by using array str directly

for (i = 0; str[i] != '\0'; i++)
   asciiArr[str[i]]++;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The variable b in main() is passed to function abc() by reference, which means that any changes made to it in abc() will also be made in main(). The parameter x in abc() is a pointer to the variable b in main().

So if you want to print the value of x that is in abc() just print the value of b that is in main(). Even though they have different names, since x is a pointer, printing the value os *x is the same as printing the value of b. Clear as mud?

Add a line of code in abc() to print the value of x and you will see what I mean: printf("x = %d\n", *x); Note the star is required because x is a pointer.

Xufyan commented: great :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>float main(void)

main() does NOT return float -- only returns int

float abc(float *x)
{
   float p;
   scanf ("%f",x);
   p=*x* *x;
   return(p);
}

int main()
{
   float a,b;
   a = abc(&b);
   printf("a = %f\nb(x) = %f\n", a, b);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably should be form2->ForwardVariable= "dummyString";

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

google for binary search algorithms.

[edit]Oops! Didn't see firstPerson's response.

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

Here is how I did it in MFC (have not used managed CLR but it might be the same). In Form2 create a public variable that holds whatever you want to pass it, then in Form1, just after gcnew line, set the value of the variable. Once Form2 starts it can move the value of that variable anywhere it wants, such as in edit box or somewhere else.

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

You forgot to include [sarcasm] and [/sarcasm] tags :)

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

>>I have just recently read over the rules.
It's about time. But better late than never :)

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

>>void writeIteratively (ostream& outfile)

That function does not have a this pointer because its not a member of a c++ class. Maybe you meant void BinarySearchTree::writeIteratively(...);

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

Look at line 30 of the code snippet you posted. See -- it has one parameter. Now look at line 23 ... there is no parameter. That's what the compiler is complaining about. You need to pass by reference the object you want to subtract.

You need to create another FancyDateClass object and pass that as the parameter. And delete line 31 -- that should be done when you create the FancyDateClass object in main. Better still you should get the current date and initialize FancyDateClass object with that instead of hard-coding some fictitious date.

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

seems to work is misleading. scanf() will scribble all over memory when you type more than 15 characters. The solution is to either use getchar() or scanf("%15s"); But with scanf() you will not know whether there are more keys or not in the keyboard buffer.

int c;
int i = 0;
while( (c = getchar()) != '\n')
{
    word[i++] = c;
}