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

>>2. Are too complicated for me to understand.
multithreading can be complicated. I use the win32 api functon CreateThread() to create a thread. Not all that complicated once you realize many of the paramters are left 0 :)

DWORD WINAPI ThreadProc(void * lpParameter)
{
    // This is the start of the new thread
}

DWORD dwThreadID = 0;

HANDLE hThread = CreateThread( 0, // Security
      0, // use default stack size
      ThreadProc, // new thread
      0, // parameter, you can pass a value if you wish
      0, // creation flags -- see MDSN for others
      &dwThreadID // Theread id to be filled in by CreateThread 
);

That is the code to create a thread. There other several complications you need to consider if both threads are to access the same data objects or use the same functions at the same time.

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

Then you didn't read the program's output good enough. If you don't add "\n" at the end of the last cout line then the text will get merged with other text such as "press any key .." making it someone difficult to see your program's output.

There is no reason I see why your program doesn't display the average.

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

>>how can someone (namely myself) tell if the code is written in C or C++?
firstly by the header files. iostream is c++ only.

>>the window closes.
Because you have to add some code to stop it from doing that so that you can see the output. The console window normally closes as soon as the main() function ends.

int main()
{
    // other code here is not shown
    cin.get(); // stop the program
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suck at text sarcasm.

Mee too :)

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

I doubt you since you are a n00b. ^
|:)

Low post count says nothing about knowledge.

Also see this thread.

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

>>Also, I have no doubt there are better ways to emulate getch(), if you know of one please point me in the right direction.

Its called curses.

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

in main() you also have to call punchmeinthehead()

int main()
{
    getlast(pastName, maxin);
    getfirst(firstName, maxin);
    getmid(midName,maxin);
	
    punchmeinthehead();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't matter where you put those declaration, just look at the changes I made to main() function.

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

Please re-read my previous post because I probably changed it since you last read it.

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

Is your program actually calling the function punchmeinthehead() ? That function looks ok to me.

I think the problem is in main(). The global variables are never getting populated because in main() you pass variable namein to all three functions and never copying the results to the global variables. You don't need namein, just pass the name of the global variable.

#include "nameinp.h"
#include <iostream>
#include <string.h> 
using namespace std;


char lastName[maxin];
char firstName[maxin]; 
char midName[maxin];

void main()
{
    
    getlast(pastName, maxin);
    getfirst(firstName, maxin);
    getmid(midName,maxin);
	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to declare the same symbols in ONE *.cpp file without the extern keyword. Such as

#include "nameinp.h"
#include <iostream>
#include <string.h> 
using namespace std;


char lastName[maxin];
char firstName[maxin]; 
char midName[maxin];

void main()
{
	const int n = 16;
	char namein[n];
    
	char lastName = getlast(namein,n);

	char firstName = getfirst(namein,n);

	char midName = getmid(namein,n);
	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in the code I posted just replace main() with any function name you wish. syntaxially it doesn't matter what function name you give it.

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

I think what you are trying to show is a normal function such as main(), and all executable code must be inside a function.

int main()
{
    char* array = new char[255];
    strcpy(array, "Hello");
    strcat(array," ");
    strcat(array, "World\n");
    cout << array;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>do all the strcpy and strcats go in {} braces?

No, except they must appear inside a function such as main().

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

>>but how do I pull that value from the size_t totallength function? do I do this?

Define a variable to receive the value returned by that function

size_t len = totallength();
char* fullName = new char[len];

>>char *fullName = new char[]; // with the box filled in

That is STILL wrong!

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

>>char *fullName = new char[];
You didn't tell new operator how many characters to allocate. put a number (or int variable name) between those square brackets.

Here's how to copy the strings

strcpy( fullName, lastName);
strcat( fullName, " ");
strcat( fullName, firstName);
// etc etc like above
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

most likely 2) your fault. You are probably not using the same compiler and/or operating system that the program's author used. Post a link to one of the programs so that we can take a look at it. And what compiler/os are you using?

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

line 37: never use eof() because it doesn't work the way you think it does.

You can easily read words one word at a time and ignore all white space by using the stream's >> operator

a combination of stringstream and fstream's >> operator should complete your program. stringstream is subclass of fstream so it has all the same functions/operators

string line;
while( getline(infile, line) )
{
     // split the line up into words using 
     // stringstream's >> operator then output a "\n" at the end
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Wow, no one after an hour? Is it that hard or did I just mess it up that badly
I was naping :)

function totallength()
The parameter must have a variable name, you can't just put a data type without a variable named. Variable names can be omotted ONLY in function prototypes.

line 26: why did you bother to calculate the total length then turn around and toss the answer into the bit bucket by returning 0 ?

You also need to add 1 for the new string's null terminating character.

You could reduce that entire function to just one line

size_t totallength()
{
   return strlen(firstname) + strlen(midname) + strlen(lastname) + 1;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use two '\' characters similiar to how you did it in the open statement. out << "Some Text" << "\\" << '\n';

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

line 168: two problems:
1) doesn't look like malloc() was everf called to allocate space for name. That will most definitely crash the program.
2) you are passing a pointer to a pointer in that function. Remove the & because name is already a pointer.

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

To use SOCKET you have to include winsock.h when compiling for MS-Windows

>>I feel so noobish. College definitely did not prepare me for my first Software Engineering Job. =X

Now you have the life-long task of really learning. You ain't seen not'in yet :)

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

I downloaded the files in that link but WinZip is not able to decompress then. The files have .tar.tar extension.

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

did you try this tutorial?

Please post a few of the link errors.

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

I think you need to count the sentences and words independently -- that is use a different index for each. I didn't compile or test this, but something like this might work.

int sindex = 0; // sentence counter
int windex = 0; // word index

for(int i = 0; i < NumfragmentsInArray; i += 2)
{
     string line = fragments[sindex++]; // sentence1
     line  += words[windex++];
     line += fragments[sindex++]; // sentence2
     line[0] = toupper(line[0]); // capatilize
    cout << line << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Anyone see where my garbage is?
No -- I keep mine in garbage cans outside my house so that the trash truck can take it away each Tuesday morning :)

Sorry if that was a bad joke. American Idol just started so I have to watch it. Be back in an hour or so to help you if nobody has in the meantime.

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

>>how we can display the encrypted image
You can't, and that's the whole purpose of entrypting it :) -- the message has to be decrypted first before you can display it so that it makes sense.

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

use a program such as Paint to draw new bitmaps then recompile the program ???

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

Here is a pretty good explaination of pair. As its name implies, and that link explicitly states, pair required two objects, not one as you have on line 7 And you can not have the name of the array the same as the class name -- the array name must be something else.

const int student_size = 12;
pair<int,int>* array[student_size];
 for (int i = 0; i < student_size; i++)   	
      array[i] = new pair<int,int>(1,i); // Construct each new pair and give its address to an index in the pointer array

I didn't compile or test the above, so use it at your own risk.

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

because you didn't do it right. google for std::pair and read how to use it.

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

What is the class of Display?


error C2061: syntax error : identifier 'pair'
error C2109: subscript requires array or pointer type
error C2227: left of '->Display' must point to class/struct/union

{
	int pair;
    const int student_size = 12;
    pair <int> * pair[student_size]; // Declare an array of pointers to Pair<int>
    for (int i = 0; i < student_size; i++);
    
	{
	pair[i] = new pair<int>(1,i); // Construct each new pair and give its address to an index in the pointer array

	pair[3]->Display(); //since Display is a member function of an object, and pairs[num] is a pointer to that object, you use the arrow operator to dereference and call the member function
	}
	return 0;
	}

delete line 3 because it hids the c++ class by the same name.

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

why use two different character arrays when you can do it directly in the original, assuming the original is not string literals

char str[] "hello world";
str[0] = toupper(str[0]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete the j loop

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

right, but you could have written your own little one-line program to prove that for yourself.

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


AD?!?! Really? Don't you mean getchar() ? :icon_wink:

Yes :icon_redface:

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

The main problem with that is that the symbol flush is also declared in std namespace. When you have using namespace std; you include everything in the entire namespace in your program. That is one of the dangers of using that statement. If you replace that with only want you need in your program than the ambiguous symbol error will go away

#include <cstdlib>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::string;

// rest of code here

Now, after getting past that, the next error is on the line you noted: and the reason is that you defined another symbol named flush that hid the original array named [/b]flush[/b] (see line 146) Delete the bool declaration on line 146 because it isn't used anyway.

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

In the first program, last line, total is undefined.

and flush is undefined in the second program. Without seeing the entire program I can't tell you why.

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

why don't you post the code that actually gets the errors. What you posted is what you want to do but not necessarily what you actually did. I know what you are attempting on line 11 can be done because I've done that quite a few times too.

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

examcode is just a simple integer (line 8). Good God man why don't you try reading your own program for a change and find out what causes the errors.

Nick Evan commented: excellent suggestion :) +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't link/or run that code because too many compile errors that you have to fix. Here are a few of them.

line 86: you forgot to change i to k.

lines 95-98 are not inside a loop, so I don't know what they are supposed to do. Looks like a posting error and those lines should just be deleted.

line 118: setw() doesn't take a float -- must be an integer.

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

>>how to initialize the code?
That means to set it to 0 or some other value, such as int exam1 = 0;

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

>>main\63.cpp(119) : warning C4715: 'main' : not all control paths return a value
Looks like you left off the return 0; at the end of main().

>>main\63.cpp(87) : warning C4700: local variable 'exam1' used without having been initialized
That error should be obvious if you look at the line in the code -- you are attemtping to use an uninitialized variable. The value of the variable on that line contains any random value, which is a no-no if you want your program to work correctly.

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

yea that's I have C# that I compile at my school then when I compile at home with VC++ 8.0 Express I have to re-write the whole thing big pain in the....

Why are you using VC++ 8.0 at home ans C# at school? Get a C# compiler (free) to use at home and you won't have that problem :)

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

He initializes 'i' the first time in line 63 then he re-initializes it in line 85

just change the int in line 85 to like 'k' or something... should fix that problem.

you are trying to assign the variable i two different values (C++ doesn't like that) if you just get rid of the 'int' initialization in line 85 or change it to a different variable label should fix the problem.

You are right but some compilers like VC++ 6.0 do not follow the rules and allow that construct. Errors like that are common when attempting to port a program written with VC++ 6.0 to a compiler such as VC++ 8.0 Express -- been threre and done that too :)

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

What is mean by this statement? I dont understand, can someone explain to me?

loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xC4C has exited with code 0 (0x0).
The program 'C:\Documents and Settings\ashida\My Documents\MASTER C++\main\Debug\63.exe' has exited with code 0 (0x0).

Just ignore it as it doesn't mean much to anyone. All that is telling you is that your program is not using the debug version of the dlls that are mentioned. It does not affect your program in any way.

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

what line number?

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

add getch() just before the return statement so that you can see the output. Otherwise your program works just great.

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

Initially assume its AM.
To convert: if the hour is greater then or equal to 12 just subtract 12 and make it PM

11:30 is still 11:30 AM
12:30 becomes 0:30 PM
18:30 becomes 6:30 PM

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
matrix[i][j]= {" ------------    ---------------------- \n","| | |____  |   | | |__ | ____    |     |\n","|  ____  |___| | | | __|_  | |____| _  |\n","| |____| |  _|_  |__     | | |  __|_ | |\n","|_|_           _____     | |_____   ___|\n","|     ___   |_   |  ________        |  |\n","|   |  |  ____   |       |  ___  |___  |\n","| | | _|      |  |    ___|  |  |     | |\n","|_| |___  |   |  | |_    |   __|__   | |\n","|  __  ___|   |______    |_______  |   |\n","|__| |___  ___   |___________| |_|_|_| |\n","|          |     |      _____|_      | |\n","| __  _____|_|___|                 | | |\n","| |     |    |  ___  |___   ___  |_|___ \n","| |   |_|_|  |  _______      |  _|_     \n","| | | | | |  |    |__________| |  _____|\n","| | |___|____| |  |  ___     __|_____| |\n","|_____  |      |     __________|  ___| |\n","|_____  |    |_|          _____|  |    |\n","|       |  | |    _|_             | |  |\n","|  | |___  |             _________| |__|\n","|  | |   | |    |    |_|_|         ____|\n","|  | |_____|    |_|_        |  | ____  |\n","|  |____|  ______   |___    |  |  _  | |\n","|     |    |            |   |  |   | | |\n"," ------------------------   ----------- \n"};

That matrix can not be initialized like that -- you have to use strcpy() to copy all those strings into the array elements.

strcpy(matrix[0],"------------    ---------------------- \n");
strcpy(matrix[1],"| | |____  |   | | |__ | ____    |     |\n");
// etc. etc

or initialize the matrix on the same line where it was declared.

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

When writing in-line functions you can not leave out the variable names. What you have on line 2 is a data type -- Date is a class, not the name of an object. Code it something like this:

Licenses::Licenses(int id, string name, string ad, Date dt1, Date dt2)
:issue_date(dt1), expiry_date(dt2) // error occurs here
{