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

The system function on line 21 does not return the shell program's return value. You will have to call some other function that spawns processes, such as one of the spawn family of functions.

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

>>i desparately need it within 4 hrs !
I see in my crystle ball that you won't make it :) Your quickest solution is to search this site for other similar questions because that has been discussed several times.

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

Please reference the line numbers in that code when commenting on the code. We are not going to hunt through all that code to search for what you are talking about. For example 3. the for-loop of the program either never ends, or is only run once. Well, exactly what line do you mean ? I'm not going to manually search all 400 lines of your program to find that.

Also tell us how you tested the code. 1. instead of 6 7 or 8, i get a value of minus 3 millions. is meaningless if we don't know how you ran the program to get those numbers. But I will take a guess that there are uninitialized variables in your program which caused that error. That would be only one of several different causes.

What compiler are you using? What operating system ? Learn to use your debugger so that you can execute the program one line at a time and inspect the value of the variables at each program line execution.

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

what easier to use c or C++ or java? (in making a game)

If you have to ask that then you are not ready to start writing a game. Study the languages first before diving into the deep end of the water.

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

Of course face-to-face is more effective because each person can easily size each up like two cocks about to get into a cock fight. You can't always know the other person's intent in the written word, over the phone, or in other forms of communications.

http://www.youtube.com/watch?v=0TiprGoV3qQ

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

very easy to read just words

#include <string>
#include <fstream>
using namespace std;

int main()
{
    ifstrem in("filename");
    string word;
    while( in >> word )
    {
          // do something with this word
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string wat is string?
Tutorial here

>>sample that will sort the 5 names to a-z
You have to understand character arrays before you will understand how to sort them. google for "sort algorithms", but from what you have already told us I doube you will understand what you read.

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

you use VARIANT just as you would any other structure.

VARIANT foo()
{
    VARIANT vt;
    vt.vt = VT_I4; // long integer
    vt.llVal = 123;
    return vt;
}

int main()
{
    VARIANT Var = foo();
    cout << "type = " << Var.vt << 
        " long value = " << Var.llVal);

    // or if you don't know the type of variant
    switch(Var.vt)
    {
    case VT_I2: cout << "integer"; break;
    case VT_L4: cout << "long"; break;
        // etc
    }
    return 0;
}

>>My initial question about a variant return type was not about a function that returns a type named VARIANT. It was about a function that could return any of several types.

That is not possible in C or C++ without using a structure or class. The AnyType class in Boost or something like VARIANT structure are the only two ways to achieve your design. You could use c++ templates but if you can't afford 16 bytes for VARIANT then you can afford the duplication that templates will create, which is a great deal more than 16 bytes.

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

>>but then when that got binned
Is binned a new slang term for drumk or intoxicated ? I know you blokes can do a lot of heavy drinking because I've seen it with my own eyes :)

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

what compiler are you using and what operating system are you working with. I know for a fact that Microsoft added exception handling in eVC++ 4.0 which is pretty old now.

>>I definitely cannot afford to turn all my variables into VARIANT types. A union of all types takes the storage space of the largest type. That is far too wasteful.


cout << "sizeof(VAIRIANT) = " << sizeof(VARIANT) << "\n";

The result of the above is 16. If you can not afford 16 bytes then you do have a very difficult time ahead of you.

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

Ancient Dragon comes from the Dungeons & Dragons role playing game that I started playing some 10-15 years (or more) ago. I still like to play Diablo LOD computer game.

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

I'll bet that was a hollywood designer dress and cost Thousands of dollars.

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

As for your other problem, here's a hint how to do all those dots

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

int main()
{
    cout.fill('.');
    cout << "1. Burger " << setw(20) << "50\n";
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>why 8 ?? since arr is counted with zero whay isnt it 7 ??
It should be 9, not 8. There are 8 characters in "pizzaboy" -- when counting the number of characters you have to start with 1, not 0. If you have a string like "p" it has 1 character not 0. I think you are confusing the way we index i nto the array. The first element of an array is 0, as shown below. That is not the same as the number of characters in the array.

corr[0] = 'p'
corr[1] = 'i'
corr[2] = 'z'
...
corr[8] = 0

Notice the last character in a string is the null-terminator 0. That's why the array must have at least 9 characters instead of 8.

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

line 42: cstr pointer has not been assigned any memory, and scanf() is just scribbling all over memory. So what are you attempting to do in lines 41-43 anyway? Since the text at line 40 does not contain any spaces then line 42 sscanf() would be the same as strcpy(), and consequently line 43 is just a copy of line 40. Delete lines 41 and 42, then change line 43 like this: string str = sentence; .

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

yup -- that means UNICODE. Set it to "Not set"

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

I've never liked American football -- too boring. European football (socker to us Americans) I like alot. So the answer to the poll is NO, I will not, nor have I ever, watched the Super Bowl. Instead I'll watch old Law And Order reruns, or Perry Mason if its on TV.

joshSCH commented: This is for not liking real football. Watch it, and you'll like it. -2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why don't you use a grid control for that. There's MSFlexGrid that's installed along with your compiler and is pretty easy to use. You can also get other grid controls such as Ultimate Grid. Then there's a free grid control by Chris Maunder. I've used both FlexGrid and the Chris's grid. Chris's grid will let you edit the cells and you can make the cells normal edit control or combo boxes. Its very feature rich and you get the source code to customize as you wish if you want to.

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

The push_back() method will create a duplicate copy of the class Catalog, and the class constructor gets called and the constructor opens a file. That means the file gets opened every time push_back is called, and eventually the program will exhaust all available file handles.

Why don't you try removing the file handling stuff from that class and add a simple >> overloaded methods. Declare ifstream in in main() then it can do something like this:

ifstream in("catalogue.txt");
Catalog cat;
while( in >> cat)
{
    catalogue.push_back(cat);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What compiler are you using? VC++ 2005 or VC++ 2008 ? Those two compilers enable UNICODE by default. UNICODE is a standardized way to use non-English languages is programs and requires some changes to standard C or C++ character arrays. If you don't care about foreign languages then you should just turn UNCODE off, as you have already apparently done.

Beyond that, sorry but I can't help you.

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

>>I am done with the first function
No you are not. Did you try to compile it? Probably not. See below for some reasons why.

Your password function has several syntax errors:
line 4: corr[8]=pizzaboy;
What is that??? If you are attempting to declare a character array to contain the name pizzaboy then you have to do it like this: char corr[] = "pizzaboy"; or like this char corr[8] = "pizzaboy"; lines 11 - 24: are all those lines part of the else on line 10? If yes, then you need to surround them with braces { and }.

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

All it is doing is calculating the number of elements in the array. sizeof(array) returns the size, in bytes, of the entire array. For example if the array has 5 elements then 5 * sizeof(int) = 20 on most 32-bit compilers. Then the sizeof(array[0]) returns the size of one element of the array. Since all elements of arrays must be the same size, which all we have to do to calculate how many elements are in the array is to divide 40 by the size of the first element, which again sizeof(int) is 4 on most 32-bit compilers.

But in your actual program you may not need that macro at all. For instance you can do something like this:

const int arrayElements = 5;
int array[arrayElements]= {0}
for(i = 0; i < arrayElements; i++)
...
...
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What the hell is that poll for? Is just plain dumb.

Ok so you posted your homework assignment. Where is your attempt to solve it ?

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

one way would be to use a stringstream object

#include <sstream>
...
...
#define SZARRAY(x) (sizeof(x) / sizeof(x[0])

int array[] = {1,2,3,4,5};
string str;
streamstring stream
for(int i = 0; i < SZARRAY(array); i++)
   stream << arrray[i] << " ";

str = stream.str() + "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm glad you found the problem yourself because I for one have no idea what you were trying to describe. Never heard of wofstream or Codecvt Facet , but I am very familary for MFC's CString c++ class.

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

When you read something from a file you can not direct it to two different places at the same time. Read the data into the array then either (1) copy the data from the array into the structure, or (2) after the entire file has been read into the array rewind the file back to the beginning and read it again into structures.

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

I personally have not done anything that REQUIRED indirect addressing. I'm sure there are some very compelling applications of it, but I don't think this is one of them. (My opinion, what's yours?)

I've seen very few times when indirect referencing is actually required and this is not one of them. For beginners the if statements work just great, and the OPs teacher would probably frown on using indirect referencing because it is too advanced for first semester students.

Also, this particular program uses the DATA as a cell address. OK if there are only 1's and 0's
then you end up with counters[0] for the zero count and counters[1] having the 1's count.
What if there is something else like a character? The program would crash. If there is a 2 in there somehow, perhaps this would push counters[] out of range.

That will not happen in this case because 0 and 1 are the only two possible values which the program inserts. If the program inserted other values then the counters array would have to be expanded to accommodate them.

I think it's kind of clever that it's "self labeling" and all, but it's also a complex way to do an otherwise simple task. I am a firm believer of the KISS method. Make the code ONLY as comlex as it it needs to be.

After you spend 20 years optimizing programs then you too will see the value in it.

To get …

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

Are you running Dev-C++ on MS-Windows? If yes, I had that error too and fixed it by changing the default include directory paths to full paths. I found that suggestion on the net somewhere and it worked for me. If that's your compiler then I'll give you more explicit/detailed information about what needs to be changed.

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

in GetHS(), line 10, I assume nRecords is the number of valid entries in the array Scores. If that is true then line 12 is incorrect. Should be this: for(int a1=0; a1 < nRecords; a1++) because arrays are numbered from 0 up to but not including nRecords. Same is true of line 24.

lint 28: indexb=indexb+a2; << wrong. should be indexb = a2; lines 43, 44 and 45. Split those lines up something like below and see if that solves the problem, after correcting the above problems.

float x = GetHS(Scores, nRecords, argOne);
cout<<"The highest test score was "<<x<<" by "<<IDs[argOne]<<"."<<endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i m trying to terminate a thread when it is executing . could anyone help me how to go about this...
thanks,
aravind

Depends on the operating system, how the thread was created and how you want to terminate it. If you used win32 api function CreateThread() then look at the link scroll down the page and it will show you several functions that you can use to manipulate threads.

The way I have done it is to set a global flag that is initially FALSE. When you want the thread to terminate, set that flag to TRUE. Then inside the thread itself you must code it to periodically inspect that thread and stop execution when TRUE is detected.

There are other ways but some of them can be dangerous.

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

Also, there is no condition set for the count. All this is doing is incrementing a cell in counters specified by the value found in matrix[3].
If say there was a in matrix[1][3], that translates to counter[0]++.
Very convoluted and probably wont work reliably.

matrix[?][3] and matrix[?][4] will always be either 0 or 1. All the OP needs to do is count the number of 0s and 1s in those two columns. So
counters[ matrix[?][4] ]++ is either counting the number of 0s when matrix[?][4] is 0 or 1s when [matrix[?][4] is 1. When all is done the number of 0s is accumulated in counters[0] and the number of 1s is accumulated in counters[1]. There is nothing convoluted about it once you understand the power of indirect addressing, and is useful in quite a few situations.

But you might be right that such a concept as indirect addressing is too advanced and complicated for beginning programmers.

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

Ok I'm really struggling with positioning, sorry.

I've placed the variable globally, and then placed the code as follows:

while (inFile >> matrix[numRows][0])
{
printf ("%d\t", matrix[numRows][0]);
for (j = 1; j < numCols; j++)
{
inFile >> matrix[numRows][j];
printf ("%d\t", matrix[numRows][j]);
}

for(int i = 0; i < numRows; ++i)
{
counters[ matrix[i][3] ]++; // count the number of 0s or 1s in the 4th column
counters[ matrix[i][4] ]++; // count the number of 0s or 1s in the 5th column
}

int counter;

I get 3 error messages:
1. Keyword 'int' cannot be declared as a variable
2. Terminating semicolon missing
3. 'numCols' has not been declared

However, none of these make sense. Hmm, I have tried, but I just can't get it?

1) counting the number of 0s and 1s can not be done until after the entire file has been read in and after the 4th and 5th columns have been completed. You put the cart before the horse.

2) int counter; What is that?

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

>>is it possible to pass two variables back from a float function.. one through 'return variable' & the other through reference

Absolutely yes. If you can't get it to work right then post the code. Here is a common way to do it.

int foo( int& x)
{
   x = 123;
   return 1;
}

int main()
{
    int n = 0;
    int k = foo(n);
    cout << "n = " << n << "  k = " << k << "\n";
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see why someone couldn't write a function named dialog() for *nix -- it obviously is not the same as a MS-Windows DialogBox. Do you have to source code for that function? If not then your only recourse is to read the documentation, and you say there is none. If you are using some sort of GUI libraries such as QT then you will find the documentation at their web site.

>>I think this is some type of NCURSES or other aftermarket implementation.
Well, what are the libraries that your program has to link with? Those should tell you where the function is.

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

>>I'm very unsure as to how to get the program to print out the results of the count? Do you have any tips?

Yes -- do it similar to how you did the other printf() lines

As for your first question -- give it your best shot and test your program to see if it works. If it doesn't work then try something else. Find out what kinds of solution(s) you can come up with.

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

>>"john williams" versus john,williams,
Because they are not the same -- one has a space and the other contains a comma.

lines 4: why are you using variable key there? Shouldn't it be id

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

user: 01234567, initial number: 106
output: 107, 110, 111, 112, 113, 114, 115, 116, 117, 120, 121.

I don't get it. How do you go from 106 to 107 then 110 etc. ? what is the relevance of 01234567?

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

one way is to use another matrix

int counters[2] = {0}

for(int i = 0; i < numRows; ++i)
{
   counters[ matrix[i][3] ]++; // count the number of 0s or 1s in the 4th column
   counters[ matrix[i][4] ]++; // count the number of 0s or 1s in the 5th column
}

The above uses the 0 or 1 in the matrix column to index into the counters array.

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

delete lines 38 and 41 because tha loop only executes once, so there is no point to having a loop there.

line 41: just make it a simple else statement. If the value is not < 0.4 then there is only one other choice, That whole loop can be simplified to this:

if (matrix[numRows][1] == 0 && matrix[numRows][2] == 0){
   rand1 = (float) rand() * RANGE / RAND_MAX;
   rand2 = (float) rand() * RANGE / RAND_MAX;
   if (rand1 < 0.4){
   matrix[numRows][3] = 0;
   }   
   else{
   matrix[numRows][3] = 1;
   }      
   printf("\t%d", matrix[numRows][3]);

   if (rand2 < 0.4){
   matrix[numRows][4] = 0;
   }      
   else{
   matrix[numRows][4] = 1;
   }
   printf("\t%d", matrix[numRows][4]);
   }

else{

   rand3 = (float) rand() * RANGE / RAND_MAX;
   rand4 = (float) rand() * RANGE / RAND_MAX;

   if (rand3 < 0.5){
   matrix[numRows][3] = 0;
   }   
   else{
   matrix[numRows][3] = 1;
   }      
   printf("\t%d", matrix[numRows][3]);

   if (rand4 < 0.5){
   matrix[numRows][4] = 0;
   }      
   else{
   matrix[numRows][4] = 1;
   }
   printf("\t%d", matrix[numRows][4]);
   }


numRows++;
printf ("\n");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i was about to ask this question too

so what's the proper way?

i always do declare globally this one

using namespace std;

Didn't you even bother to read the rest of this thread ?

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

your while statement is incorrect

while( infile>>thisdate )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to remove the key from the keyboard buffer

if( kbhit())
{
    getche();
    y++;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

worked ok for me using VC++ 2008 Express on Vista Home Premium. I had to press Ctrl+Z followed by <Enter> keys.

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

I'm still in school I will have my degree May 09. The career service placement at the school is not great and they don't have anything. The reason I posted this was because I thought people in the Industry might have some different ideas.

Check with some local head hunters (employment agencies) and ask if they have any internship jobs available. Quite a few companies in my area hire them on temporary basis.

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

go back to school and get a degree. If you can't get a degree because you can't do the work then just to go McDonalds and flip hamburgers for the rest of your life.

Also check with some of the temp employment agencies in your area to see if you can get an entry-level job.

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

google for that error number shows several threads about it. Here is one of them that may be helpful to you. The most likely cause is a missing header file, or an error on a previous line(s)

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

if fix is a string then how on earth do you expect this to work: fix = 0146; ???? what are you trying to do here ?

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

how are fix and username declared? I would presume from the name of the variable that username is a character array. Then why are you assining an integer to a character array? Doesn't make sense.

If you want to debug that switch statement it is easier if you put those statements on separate lines, like this:

case 0:
    fix = 1046;
    username = fix;
    c = 1;
    break;

The second problem with that switch statement is that there are no break statements to prevent executing all those statements. For example: if case 0 is executed the program will also execute all the other cases because there are not breaks. See the example I posted above.

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

lines 14 and 22: names is not a valid pointer because names is declared wrong on line 5. What you want is this: char name[200][20]; and assume the length of a name will never be more than 20 characters.

I think you can combine lines 14 and 15 like this (untested): fscanf(fp, "%f,%s", &numbers[i], names[i]); >Last little problem, when parsing numbers, I get somewhat strange results, for example 17.34 turns into 17.340001 or 23.31 turns into 23.309998 , why is this happening?

That's the nature of floting point numbers and has to do with powers of 2. Many numbers can not be represented exactly with floats and doubles, which is why you can't test them for equality with the == operator. To get an in-depth explaination you would have to read the IEEE standards, available free on the net.