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

That error means the linker can not find a library. Check your computer file system to see if it exists. It has nothing to do with the code you posted.

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

line 2 in your first code snippet: use the boolean == operator instead of the assignment = operator.

lines 4-7 -- you need to use braces "='{' and '}' in order to put lines 5-7 inside the else block on line 4.

In the second code snippet its difficult to see what is going on because it is so poorly formatted.

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

If your using Linux the "time" command will do nicely.

time() resolution is only to 1 second -- not accurate enough for profiling. clock() however normally has a resolution of 1 millisecond.

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

You are using the fread function incorrectly by swapping the position of the second and third parameter. The second parameter is not the size of the entire file, but the size of each chunk.

Try changing to fread(iobuf, nblocks, filesize, in) and it should work out to be fine.

I don't think it makes any difference -- I usually do it the way the OP posted and have never had a problem. But, as Narue will probably say, in general it may not be safe to do that.

echobase: post your current program and attach a copy of the file you are working with.

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

one way is to buy a commercial profiler program :)

But the easiest way is to call clock() to get the current time before starting the algorithm, then call it again after the algorithm is finished. The difference is the execution time. But be warned that the algorithm might execute so quickly that the time is unmeasurable. In that case call the algorithm in a loop for maybe a thousand or so times.

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

my guess is the screen is not 24x79. Try increasing the value of dx to test that out unless, of course, you have already thought of that and tried it.

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

line 44 should have read < filesize because it is reading filesize bytes.

>>But can you tell me if in the for loop I should be reading each char in ptr into a new target array that should then be passed to an fwrite function for streaming to the target file

No you don't have to create another array. In the for loop I posted just use fputc() to write out each character one at a time. The operating system will buffer them up and optimize the write to disk.

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

1. Open the file for read, call fseek() to seek to the end of the file, then call ftell() to get the length of the file. Alternatively you can get the file length by calling stat() or fstat().

2. Allocate a buffer pointer to the file size obtained in #1, above.

3. Read the entire file into that buffer -- you can probably use fread() to read the file all in one shot (assuming the file is small enough).

4. Use another char pointer to transverse the file from end to beginning of the buffer. Something like this example

char *ptr = 0;
char *iobuf = malloc( fileSize );
fread(iobuf,fileSize,fp);
for(ptr = iobuf; ptr >= iobuf; ptr--)
{
    // do something with the character at *ptr
}
free(iobuf);

Note the above code snipped does not contain any error checking, which you should add in your program.

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

>>Can Dani or her team member answer my question so we can close this?

HappyGeek already did in his post immediately following yours.

>>And what I see after few posts? Some of the members starting flaming war between them ! ! !
I agree, and they are walking on thin ice (meaning infraction) if they continue that.

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

in that case just change line 9 to pass CButton.c_str() and it will compile ok.

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

line 6 does nothing -- delete it.

>>problem is that CButton needs to be a const char
No, it needs to be const wchar_t* because you are calling the UNICODE version of ShellExecute. You will have to convert c_str() to wchar_t* which requires another function to make that conversion.

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

you must use the initialization list version to initialize references. Otherwise I don't think there is a difference. I prefer the version I posted whenever possible.

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

Here is a good explaination.

doubles have greater precision than floats, so if you view the raw value of 0.7 a double might be 0.7000001 while a float might be 0.7000

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

Its just another way of initializing variables -- those could have just as easily been coded like this:

CDriveControl::CDriveControl()
{
     m_pPort = NULL;
     m_pSPTIDriver = NULL;
     m_bInitFlag = NULL;
     m_onlycomp = NULL;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The result does not have decimals because 9 and 5 are both integers and 9/5 returns an integer. you are typcasting the result of the division which is 1 to a float. Read Salem's example for the correct way to do what you are attempting, unless you want to get really brillent and appear to be super-smart and do something like this: :cool:

celsius*static_cast<float>(static_cast<float>(9)/static_cast<float>(5))
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the parameters to main() can be in one of two forms

int main(int argc, char **argv)
{
}

or
int main(int argc, char *argv[])
{
}

Both the above are identical and access individual arguments the same way. Convert the third argument like this (recall argv[0] is the name of the program).

int main(int argc, char **argv)
{
   int n = atoi(argv[2]);
}

There are several functions that convert a string to int or long and all are normally acceptable, atoi() is only one of them. atoi() does not provide for any error checking, so if you are concerned about possible errors in the argument string then you should use one of the other functions.

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

I don't think any of them fit me. Would like to think #11 does, but it doesn't. I voted before taking the test -- can I change my vote now :'(

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

Also once in college you might be able to shorten your time there by taking bypass tests to get credit for the material you already know. No point in being bored in class listening to elementry stuff you have already studied.

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

delete line 13, it has no purpose.

change line 25 to use pointer pS

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

yes, I think you have the right idea. The prototype might look something like this:

void foo(int* prm1, int* prm2, int* prm3);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program should probably call UpdateWindow() to force the WM_PAINT message to be put into the message queue. Have you read MSDN OnPaint description?

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

what compiler are you using? I just compiled with VC++ 2005 Express and got no such error message, although I did get several others because you tried to make the return value of sizeof operator negative. Just typecase sizeof to return int and that corrects that problem.

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

I agree with this poster.
Suggesting multi-threading to a beginner programmer is like giving a gun to a 3 year old. And since we're talking C++ here you can be damn sure he'd reuse the bullets!

What needs to be conveyed to the original poster is what design patterns can be used to achieve the desired effect.

Don't shoot the messenger! Brent asked about multi-threading, so I pointed him in that direction. I won't pretend to know his skills or read his mind.

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

>> need to learn how to multitask in c++.

Its called multi-threading. Here are more information.

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

>>you can call the function at any point of the program
that may, or may not be recursion. recursion happens only when the function is called somewhere within the same function. For example

void foo()
{
<snip>
    foo();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

do it all on one line

IPHeader_format IPHeader1 = {1 , 4 , 5 , 0 , 1500 , 1 , 0 , 0 , 8 , 4 , 0 , 0 , 65535};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see anything wrong with it. Maybe its just your eyes, or maybe they fixed it.

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

use a stucture, like this

struct num
{
    unsigned short v1: 4;
};

int main()
{
    num var;
    var.v1 = 5;
    printf("%d\n", var.v1);       
    return 0;

}
Aia commented: Very clear +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>>fflush (0);
>That is non-standard
No, it's well defined by the standard. If the argument is a null pointer, all open output streams are flushed.

true, fflush(stdout) is well defined, 0 is stdin not stdout

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

you sait you have to use vector, just replace the array with a vector as mentioned before. If you don't want number_used then delete it from the program. Give it a try and repost your most recent attempt at solving the problem.

vector<int> sample_array;
sample_array.resize(10);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ has a sort() function, all you have to write is a comparison function. Here is a short tutorial

If you want to keep all the code you have already written, just replace the array with a vector, then call the vector's resize() method to initialize it to contain 10 elements. I think the rest of the program should work without change.

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

Does anyone else want them back as well?

No, can't say that I would find them useful. I do, however, use "Posts Since Last Visit" and "Todays Posts" a lot.

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

sprintf() will do it -- the format string is "%x" or "%X"

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

you probably need to add more braces, like this, and don't put braces on the same line as other code because it makes the program moe difficult to read and understand. Strive for clarity, not cuitness.

int main()
{
   for(int i=0;i<=7;i++)
   {
        for(int j=0;j<=i;j++)
        {
            cout<<'*';
            for(int k=0;k<=i;k++)  
            {
                   cout<<' ';
             }
        }
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hello ,

first i want to say that im very new at c++ , i managed to create a very simple program through searching the internet , this little program involves running a certain exe file with parameters :

(e.g: "c:\folder\file.exe" -parameter1 -parameter2)

i am using the system() function to do that so my code looks something like

string x;
x = "\"c:\\folder\\file.exe\" -parameter1:value1 -parameter2:value2";
system(x.c_str());

so it would run this command ( "c:\folder\file.exe" -parameter1:value1 -parameter2:value2 )

it works fine untill one of the parameters values must include quotes in it like this ( -parameter:"value" )

so when i type the code like this

string x;
x = "\"c:\\folder\\file.exe\" -parameter1:\"value1\"";
system(x.c_str());

i get the error :

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


but if i put the same command line ( with the quoted value of the parameter ) in the windows run , or in CMD , it would work fine, why do i get the error when i try to run it from the system() function ..?!!


i appereciate any help.

Check the quotes in the line you posted, there are too many of them. -- remove the quotes at the beginning of the string and after file.exe. It should be something like this (I tested it and it works)

system("\\dvlp\\file.exe -parameter1:value1 -parameter2:\"value2 with spaces\"");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe they mean the circumfrenece of the circle that surrounds the triangle ?

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

Circumference of a Triangle ? WTF !!!

Didn't you learn anything in school -- its a tringle with rounded corners:)

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

you should not mix C and C++. In C++ use cin.ignore() to pause the program instread of C getchar(). And you don't need stdio.h either.

#include <iostream>
using namespace std;
int main ()
{ 
    cout << "Hello World"; 
    cin.ignore();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>fflush (0);
That is non-standard, should be fflush (stdout); . Any attempt to use fflush() on an input stream like stdin will result in undefined/unpredictable behavior.

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

>>i did that but i am still comeing up with errors except these errors that are coming up shouldnt be there

what are the errors? Compilers do not produce errors unless there are infact errors. For example: look at lines 63-66. Line 66 is an error because of missing braces to enclose lines 64 and 65 in the same block.

Line 74: two problems here. (1) using the '=' assignment operator instead of "==" boolean operator (very common mistake), and (2) missing semicolon at the end of the line.

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

1. initialiseBoard() is writing out-of-bounds in that matrix because those two loops are executing 1 too many times. Replace <= with just <

2. delete line 31.

3. delete line 95. the array is never referenced in that function.

I don't know how you will test any of the rest of the code because none of the functions are ever called. You need to add a little code for options a and b to call the other functions.

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

50 characters for a directory name isn't enough space. What if I copy/paste a path that is more than 50 characters? You need at least 255 characters.

line 23: that does nothing. Delete that line.

line 43: ditto -- nothing more than a do-nothing line.

Now for your question: On line 38 you need to re-initilize the variable destination with the text "cp ". just use strcpy() for that strcpy(destination,"cp "); I think that will fix the problem.

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

you don't need function moreToRead() Change lines 27-31 to be something like this:

while( getline(in,line) )
{
   // blabla
}

What format is the file? FirstName LastName <scores> ?

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

My contention is that teens aren't bad drivers, but they are inexperienced drivers. The sad truth statistically is that the largest amount of teen deaths is because of automobile accidents, and most of these accidents are related to speeding.

That makes anyone a bad driver. A good driver will rarely, if ever, have accidents. Although here in St Louis a teen is more likely to get killed with a gun then with a car.

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

also delete line 12, don't have to declare that only once at the top of the program and after the includes.

>>How do I make it execute the function once then return to ask if there is another amount

move lines 17 and 18 up above line 15. Also, there is no need to make sales a global variable. Move line 3 to be local to main() then pass it as a parameter to salesInput() function.

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

remove the semicolon at the end of line 13. That's a common mistake for even old-timers -- you just need to learn how to recognize the error.

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

That error message seems pretty clear to me -- it means that your compiler can not compile that program because it contains code that is no longer supported. You will have to use an older Borland compiler, such as Turbo C.

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

strtok() is not what you want. The text in string2 may or may not be a complete word surrounded with spaces. It could be a few letters of some larger word. Better if you just search string1 for the first character of string2. When (and if) found check if the rest of the characters in string2 follow. If not, then continue searching string1 for first character in string2.

If you know pointers then the job is a little easier. If not then you can use loop counters to index into the two strings.

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

works ok for me.

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

>>What I am trying now is to reduce the number of lines.
That doesn't mean you have a poor program. Pure assembly programs are typically very huge.

one way to do it is to write a small program in C that demonstrates the problem you are trying to resolve then have your compiler generate the assembly code (I know that all Microsoft compilers have that option). That way you can see how any given algorithm works.

Salem is correct -- programming in assembly is the hardest possible computer language (except programming in pure machine code). And that's why the really good assembly programmers will make more $$$$$. And its why not very many people do difficult tasks in assembly.