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

I have never seen a byte defined by anything other than 8 bits, although I don't thinnk the c or c++ standards specify its size. Here is just one of many examples.

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

>>arely ever leave the house in the Winter
That's where most colds come from. You don't get a cold from cold weather, but from other people.

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

Yes I LOOOOOOOOOOOOOOVE yogurt, one of my favorite foods. Taks a cup of plain unflavored yogurt, a cup of cottage cheese and 1/2 cup blueberries (or other fruit), mix in blender, and you have a great drink. I've also used unsweetened jello mix.

Daily doses of yogurt has proven to have other good benefits for women. So if you (the reader, not Walt!) are female you should consider adding yogurt to your daily diet.

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

The clock function returns the number of clock ticks that have elapsed since the program started. One clock tick is typically 1 millionth of a second (called a millisecond) but it doesn't have to be. The macro CLOCKS_PER_SEC is the number of ticks per second. So if clock() returns a value of 2000000 then that is 2000000/CLOCK_PER_SEC or 2 seconds.

The line diff = ( std::clock() - start ) / (double)CLOCKS_PER_SEC; is just calculating the difference between the current time and the previous time, then converting it to seconds.

>>it looks like a lot of uninitialized variables
Look closely and you will see that his code initializes the variables correctly. Initializing variables to zero or some other value when declared is a good habit to get into, but its not absolutely required as long as the variables are initialized someplace before attempting to access them.

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

>>if anybody knows how to check text for a specific string and then change it or create a message box(ie. swear detecter)

If you are looking for a way to detect obscene language, you might ask Dani because she implemented something similar for DaniWeb a couple months ago. I don't know enough about it to describe how its done.

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

If you make the variable k static then it will work because static variables are similar to globals except they only have scope within the function in which they are declared.

void changep(int*&p);

int main()
{
    int*p;
    int x;
    changep (p);
    
    cout << *p;
    x=*p;
    cout << x;
}

void changep(int*&p)
{
    static int k=3; // <<<<<< Here
    p=&k;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call clock() before starting the code you want to profile then again after the code finished. The difference is the approximate executation time. Since the code runs very quickly you probably have to run it quite a few times to get any measurable results. In his example he ran the print function 1,000,000 times. If you want the execution time per iteration then just make the simple division. (total time / number of iterations).

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

1. you can not statically link a dynamic link library (DLL).
2. The os calls DLL initialization, your program does not do that. Each DLL has a dllMain() function which is similar to main() in C programs. It is called by the os when the dll is first loaded into memory and its job is to do all dll initialization.

3. your program only calls the function it wants to use in the dll. See #2 above.

One thing to keep in mind: all memory allocated in the DLL must be deallocated in the DLL because the memory is allocated in a memory pool that the application program does not know about. And the reverse is true also -- memory allocated by the application program can not be deallocated in a DLL.

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

I am on my way out to spend time with the lady, but can't wait to get back and try again.

Yes, certainly. Glad you keep your priorities straight:cheesy:

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

yes I have too, but thought it was just my internet provider or something. Its also somewhat slow loading the whole page, half will load ok but the ramainder (probably menus) takes a while. In the meantime I can't use the vertical browser scrollbar.

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

>> was told that I might try writing programming "pearls

A common problem is to write a function that validates user integer input. It would get the value from the keyboard as a string then parse the string for illegal characters. If any illegal characters are found display an error message and ask for input again. Finally when no illegals are found convert the string to int and return the value.

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

0xFF is the largest value that can be stored in one byte, for signed integers that is 0xFF/2, which is 127.5 (use a calculator if you must). Since you can put 0.5 in a byte, one side is 127 and the other is 128 so that 127+128 = 255 (0xFF).

limits.h contains the upper and lower limits of all numeric data types supported by your compiler.

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

>>(Hint: Use the function pow from the header file cmath to calculate the square root.)

That is in error. the pow() function raises X to the power of Y. you need to use the sqrt() function to get the square root of a number.

In the equation
(-b +/- √b^2 – 4ac ) / 2a


first find the value of b^2-4ac using the pow() function to get b^2. Then use sqrt() to get the square root of that result. That gives you
(-b +/- sqrt(result)) / 2a where result is the previous computation.

Now you need to make two computations to get the findl result
(-b + sqrt(result)) / 2a
and
(-b - sqrt(result)) / 2a

Note1: that when the term b^2 – 4ac = 0, then the equation has a single (repeated) root. -- which means you do only one final computation, not two as described above because the value of result will be 0 making the result of both final computations the same. (-b + result)/2a is reduced to -b/2a

Note2: when b^2-4ac < 0 you can not do any of the other computations because the square root of a negative number is a complex number, not a real number. Most c programs can not deal with complex numbers, althrough there are advanced math libraries which can. But you are not at that level, so don't worry about it. I would just display a message that …

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

It is C code except the vector class. Just replace vector with a 2d char array and add malloc() where needed to allocate memory for the strings. You wouldn't want to turn that in as your assignment if you have not covered recursion yet because your teacher will know the difference.

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

I don't see the problem you describe. Do a print screen and attach the bitmap file to your post so that we can see what you are looking at.

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

Here is a brief explanation Only the first couple paragraphs may be relevent to you.

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

you will want to use recursion to process the directories. Here is an example of how to do that.

[edit]After looking closer it will take a little bit more to port that. you will need to know about linked lists and arrays. [/edit]

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

Oh. I see it has not been fixed yet. Looked ok earlier today, but guess I must have been looking at something else.

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

Yes your teacher is correct -- returning the db object like you did is very wasteful of system resources and time.

What I would do is pass a reference to an existing db object to makeDb() so that it does not have to return the object.

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

erg i take it back. The problem i'm actually having is with trying to return something by a method called 'return value optimization.' I can't seem to create a copy of the db in the function to the one in in main.

There is no such function in the code you posted. And function names can not contain spaces.

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

you mean a vector like below? There are probably other ways too, but this is how I do it.

vector< vector< string> > theList;
vector<string>::iterator it;

vector<string>& innerList = theList[0];
it = innerList.begin();
for( ; it != innerList.end(); it++)
{
  // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not unless you pass a pointer to the pointer in main(). Something like this thread from yesterday.

Also you must make sure the object in the function will not go out of scope then the function returns to main(). Objects created on the stack do not exist beyond the lifetime of the function in which it was declared, so when the function returns to main the pointer will have an invalid address.

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

your program never closes the file (never calls fclose() ). There is a finite number of files that can be open at the same time -- years ago the limit was 20, but MS-Windows is a lot more.

why are you mixing c and c++ code? If you are writing a c++ program you should probably use c++ fstream, not C FILE. Also should not mix cout and printf(), use just one or the other for consistency.

You can greatly reduce the amount of code you have by using a do loop instead of a while loop as I illustrated later. Right now it looks like you have everything coded twice, which isn't necessary with a do loop.

as to your question why it can not open the file: Probably because the current working directory is NOT in "c:\test". Is that the directory where the *.exe program is located? If not (and probably not) then you have to add the full path to the file name. FindFile() does not do that -- it only returns file names with no path information. Something like this:

char filename[_MAX_PATH];

...
strcpy(filename,"c:\\test\\");
strcat(filename, FindData.cFileName);
fp = fopen(filename, "rt");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to write a windows application, not a console application. Here is an example program.

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

Unfortunately that's a bug that I spent almost an hour trying to fix yesterday to no avail. I'm going to take a little break from it until I come up with another idea to try. Essentially playing with the z-index CSS property should fix it but it doesn't and I don't understand why not.

Looks like you got it fixed :) Looking good now.

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

If you don't post your code there is nothing anyone can do for you, except maybe give you a little sympathy.

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

get keyboard input as a string then do whatever you want with the individual digits.

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

>>//function call computeProduct(product *pProduct,int *pBest);

Do not include the data type in the function call, just the variable name, like this: computeProduct(pProduct, pBest); Q2: Error checking is a little more difficult to resolve; there is no simple way to do it. In your case I would get keyboard input as a string and then parse the string for illegal characters. Or get keyboard input one character at a time using get() function and test it for illegal characters.

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

which operating system and compiler are you using?

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

>>int y = str[i2];

str[i2] contains the ascii value of the character, such as '1' is ascii value 49. See this ascii chart for all of them. To convert it to decimal just subtract '0' int y = str[i2] - '0'; >>a += (h_str[h_str.length() -i2]) *x;
I have no idea what that is supposed to do. where is h_str declared ?

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

oh? 60K what would that be, and per what?
If Turkish Lira per month, yah, you can get more in Europe.
If USD per month, forget it (especially as an entry level salary).

For experienced people (5-10 years), expect between 30 and 45K Euro per month (outside London, which pays more because of the extreme cost of living).
For entry level positions, 20-25K at most (I started at something like 12.5K 10 years ago).

Don't you mean per year ? 30-45K per month :eek: I'll move to Europe for that. 40-60K per year USD is about right for entry level position depending on education and location.

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

are you seeing double? :cheesy: I don't see anything unusual in those threads.

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

you need to repost your code so we can see what you have done.

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

what error message do you get?

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

Hello Meshia -- welcome to DaniWeb. Hope to see you around soon.

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

There is Windows API function, see thread:
http://www.daniweb.com/code/snippet217.html

You posted the wrong link.

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

Ok here's the same thing in C

do {
  //check for . and ..
  if( strcmp(FindData.cFileName,".") != 0 &&
        strcmp(FindData.cFileName,"..") != 0)
  {
        FILE* fp = fopen(FindData.cFileName,"r");
        // do something with this file
        //
        // now close the file
        fclose(fp);
        fp = 0;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know what window() does.

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

since the fstream is global (bad programming habbit) after closing the file you have to clear the errors.

is.close();
is.clear();

A better solution is to make the fstream object local to the function, or pass a reference to it.

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

what operating system? on *nix just open a pipe to the ps program than parse its output. There are probably other ways to accomplish it too.

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

gotoxy() was NEVER EVER a standard c or c++ function, but it was a Borland-specific function that started with Turbo C. No other compiler that I know of implemented that function.

See this to implement the function yourself

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

Hey Dude -- apparently you are the only one who used an iPod :mrgreen: I don't own one either -- I just got my first cell phone for Christmas and I rarely use it.

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

>>void foo( char * ptr)

The problem is that ptr is a local object which has scope only within the function foo(). So the memory allocated with malloc() will be tossed into the bit bucket as soon as foo() returns to main(), and that will cause a memory leak. Inside function main() the value of ptr will still be 0 after foo() returns and the next line, printf(), will probably crash because the second argument (ptr) is a NULL pointer.

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

fscanf() does not differentiate between rows. So you will be better off not using that function at all. Instead, I would use fgets() to read one row at a time then parse the string that was read.

char line[80];
char *ptr = 0;
int i = 0;

while( fgets(line, sizeof(line), f) != NULL)
{
   // clear the array
   memset(v,0,sizeof(v));
   i = 0;
   // extract numbers from line string
   ptr = strtok(line," ");
   while( ptr != NULL)
   {
       // insert into array
       v[i] = atoi(ptr);
      ++i;
      // get next number from the string
      ptr = strtok(NULL, " ");
    }
    // now do something with these numbers

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

moved to more appropriate board

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

your question is not very clear -- what exactly do you want to do? This will move a binary file into ax register

mov ax, 01010101B
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do that in assembly language? Its a whole lot easier in one of the higher-level languages such as C, C++ and basic. And how to communicate with those depends on the operating system and the hardware manufacturer-- there is no standard way of doing it.

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

I don't know about phthon but I know that can be done in C or C++ using sockets. Computers attached to a LAN (Local Area Network) do not require internet service provider but others do.

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

argv parameter of main is a good and common example of a double pointer -- it is a two dimensional array of strings. It can be coded in two ways and the use of the argv is identical in both version.

int main( int argc, char **argv)
{
    // print the first string
    printf("%s\n", argv[0]);

   return 0;
}

or

int main( int argc, char *argv[])
{
    // print the first string
    printf("%s\n", argv[0]);

   return 0;
}

The other example where the double pointer is a pointer to a pointer, lets say you have a function foo() that allocates memory for a pointer that was declared in function main()

void foo( char ** ptr)
{
   *ptr = malloc(255); // allocate some memory
   strcpy( *ptr, "Hello World");
}

int main()
{
   char *ptr = 0;
   // call function with a pointer to pointer
   foo( &ptr );
   printf("%s\n", ptr);
   // free up the memory
   free(ptr);

   return 0;
}
NicAx64 commented: Thanks for the example ,helps me alot +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I used VC++ 2005 Express to test your code.