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

there are several ways to convert a string of digits to an integer. One of them is by using c++ stringstream class, which is based on fstream but works on strings instead of files

#include <string>
#include <sstream>

int main()
{
    char digits[] = "1234";
    int x = 0;
    stringstream stream(digits);
    stream >> x;

    cout << x << "\n";
}

And converting from int to strring is just as simple

#include <string>
#include <sstream>

int main()
{
     int x = 12345;
    string digits;
    stringstream stream;
    stream << x;
    stream >> digits;
    cout << digits << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are thousands of free programs at www.codeproject.com.

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

x = tolower(x); is how you convert the character in variable x to lower-case.

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

>>'fopen' was declared deprecated
That's only a microsoft warning. You can just ignore it because the c++ standards has not made it deprecated.

FILE, fopen() and all associated functions are declared in stdio.h, not iostream or fstream. In c++ programs you really should not be using those C functions, in otherwords, the file is not in the directory you think it should be in.

The problem is NOT with fopen() -- looks like you coded it correctly. I suspect you are not specifying the correct path to the file.

There is a pretty easy way to tackle your program. There are at most 255 possible characters, and less than half can be typed from the keyboard. So if you make an array of size 255 then when a character is read you can simply use that character as an index into the array and increment it.

int counts[255] = {0};

char line[] = "Hello World";
// count the number of characters in this string
for(int i = 0; line[i] != 0; i++)
   counts[line[i]]++;

Now when the above loop finished, the array counts will contain a list of the number of times each character appears in the string. You can do this for an entire file if you wish.

To find out the characters that appeared in the text just check the array counts for non-zero elements. The letter 'H' has an ascii value of 72 (look it up in any ascii chart), so counts[72] …

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

your voting system is so complex

Right now we are not voting for a President. We are voting for someone to run for President, and that election is in November when everyone votes at the same time. And its even more complicated than that -- in November we don't really vote for the President but for a bunch of people (electorial college) who will meet in January to elect the President.

There have been many attempts to abandon the electorial college system over the past 250 years, but none of them succeeded.

Yes, it is complicated.

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

That doesn't tell much. Appears like the program is just writing one word to the file then attempting to read it back. The open() statement you have will erase everything that's already in the file. If you want to add more words every time you run the program then you have to use ios::ate as the second parameter in that open() statement. ofstream myFile ("words.txt", ios::ate);

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

Looks like the Demo Convention could become quite a 'hate festival'. Good for McCain!

This will certainly be an interesting convention. The democrats have an excellent chance of winning the presidency, lets hope they don't blow it at the convention. I read somewhere that Al Gore might even get the nomination if nobody gets it on the first round of ballots (A brokered convention). The way I understand it is that the delegates are only committed for the first pass during the convention. After that they are free to vote for whoever they want including someone who didn't even campaign.

The last brokered convention to yield a nominee that went on to win the general election was the Democratic convention in 1932 that nominated Franklin Roosevelt.

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

were you in vietnam ancient?

Yes but I wasn't a pow. They wouldn't even let me have a gun for fear that I'd soot everyone but the enemy.

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

>> dont know how to display the contents in my program

You only use one set of code tags. I deleted all your code because its too much trouble to fix., so please repost and use code tags correctly. Here's how to do it.

[code=c] // put your code here

[/code]

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

Bitwise operators

The last one, line 15, is just null-terminating the string. The author could have simply use 0 instead of 0x00.

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

Nice code -- works perfectly on my computer :)

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

use void main() instead
and add system("PAUSE") at the end after the cout statement

You obviously have no clue. Read this.

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

Thread closed to stop potential flame war.

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

I have no clue what you want.

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

I don't really know anything about that raw_open() function, but from this vb example the parameters are supposed to be of type _variant_t, not BSTR.

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

you can write a wrapper function in the *.cpp file that the C function calls, then let the wrapper function call the class method. The following function can be called by C programs.

// c++ file
extern "C" int foo()
{
    // call c++ class function
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>What do you mean by the functions having an internal linkage?

Explaination here:

>>Also, from my understanding, an anonymous namespace is just one without a name, so how would I call that?
The same way you do all other functions in the standard C/C++ libraries (other than class libraries). None of them are defined within a namespace. Just don't declare a namespace for them.


>>The guard would be so I don't call unwanted functions, right? But isn't that implied of an anonymous namespace?

No. Code gards are a completly different issue, and has nothing to do with namespaces.

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

you didn't post application_tel.h, but most likely the reason for those errors is that that file does not include another header (appication.h).

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

line 8: you changed it wrong. What you now have is just a single character. Look at your previous program and change it back to the way you had it before. char name[80]; >>so if cin.getline(name, size of(80)) right?
Wrong. its sizeof(name) ,

>>the "size of(80)" here is the same as char name[80]?
Nope.

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

getline() is declared in <iostream>

In the red part you posted, the first parameter to getline() is the name of the character array to receive the characters you type, similar to the first parameter to gets(). The second parameter is the maximum number of characters allowed in the input buffer. The sizeof is an operator that returns the size of the array. So if you defined char name[80]; then sizeof will return 80.

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

>>but if i don't use gets() the white space will not be read. The space for example
WRONG. getline() reads everything including white space up to the '\n' character.

>>whats the difference w/ getline() and gets()?
getline() is c++ and works perfectly. gets() is old C and will trash your program if you are not very very careful when you type (don't type more characters than the input buffer can hold).

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

What about inheritance do you need help with?

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

you don't need cstdio header file, and never ever use gets() even in c programs. Use getline() in c++ to get strings

cout<<"input your name: ";
cin.getline(name, sizeof(name));

You don't have to use cin.ignore() after getline(), only after entering integers

int x;
cin >> x;
cin.ignore();

read this thread for a more complete discussion.

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

>>Which means writing to the cout stream will only be done by one thread.
Not so.

They are both calling the same function but it is still in two different threads. It will be easier to synchonize the threads that way but they must still be sychronized. And they will also be accessing some ready state object, can't do that either without synchronization. The only safe way is via semiphore or critical section to lock entire functions.

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

That may not work because two threads may still access the stream at the same time. Safer to use a sepaphore to lock the threads.

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

I would have a foul mouth too if I spent 5 years (or whatever) as a POW in VietNam. Not a pleasent experience.

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

Your test program illustrates the need to synchronize the threads for use of cout. cout is not thread safe, meaning your program could lock up if you don't take precautions. There is an article I found that is only ONE way to solve the problem.

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

God I love you. I was able to make 2 simultaneous running threads so easily it is funny.

Please deposit $1,000,000.00 USD in my PayPal account :) Glad I could help.

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

>>30: error: `cout' undeclared (first use this function)

Uncomment line 4 :)

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

line 1: there is no such include file. Just delete that line

line 26: wrong number of parameters. See that function's prototype on line 9.

lines 23 and 27 and 69: sub is declared as a function on line 10. You can't use the same name as a parameter.

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

Did you read you PM that I sent you? Here's how to add the code tags

[code=cplusplus] // put your code here

[/code]

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

[edit]nevermind. You already fixed it.[/edit]

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

You didn't answer all my questions.

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

your program has a couple problems:

1) you must declare main like this: int main() . You can't leave off the return type.

2) you need to strip the '\n' character out of the keyboard buffer after each cin. There are several ways to accomplish it, but this method will work if the only character is '\n'. For a more complete discussion see Narue's thread here.

cin >> age1; 
cin.ignore();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are mixing C and C++ -- not good for your grades. for input gets() is NEVER EVER recommended even in C programs because it can screw up your program. In c++ use either cin or getline.

cout<<"Please enter a user name to setup\n ";
cin.getline(charname, sizeof(charname));

You still did not fix that if statement like I showed you (which is why I wanted you to repost your code). Go back and re-read my previous post paying very careful attention to the correction I made to that line.

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

>>P = (rho * g * delta_h_water) + 1 atmosphere

int P;
int rho;
int g;
int delta_h_water;

//set those values to some values is not shown
P = (rho * g * delta_h_water) + 1 );

>>V = pi r^2 * h

#include <cmath>
double V;
const double pi = 3.1416 // add as many digits as you want
double r;
double h;

f = pi * pow(r, 2) * h;

>>P2 = P1V1/V2
Assume P1, P2, V1 and V2 are all integers. Make sure V2 is not 0.

int P1, P2, V1, V2;

p2 = (P1 * V1) / V2;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I need help work wil not compile
Same questions as I posted in your other thread. I'm not a mind reader and I can't see your monitor.

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

>>Whats am i doing wrong it is not compile
Errors ??? compiler ? operating system ?

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

Do the requirements one small function at a time. Code, compile, fix erorrs, then compile again. Repeat that until all errors have been fixed before doing any more of the program. You can start like this:

#include <iostream>

int getDrawers ()
{
   // put your code here
}

// make other required functions similar to above

int main()
{
    // put your code here
}
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

line 5: remove the open parentheses after =.

line 8: replace close parentheses with a semicolon

lines 9-17: you can not put the calculations here because the value of input is not yet known.

line 20: its a big mess :) you are mixing c's printf() format specification with c++ -- you can't do that. Forget the %d specifier. Format the text like this example:

cout << "half_dollars = " << setw(11) <<  halfDollars << "\n";

You never did prompt for data input and use cin to get the values from the keyboard.

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

>>Any ideas?

Yes -- post code.

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

You've added a lot of great comments and helping others. Keep of the great work :)

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

Welcome to DaniWeb. Post your question in Tech Talk and I know someone will be able to assist you.

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

Welcome to DaniWeb. I know you will find lots of help is only you ask.

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

Walking is never a waste of time -- it keeps you physically fit. After I graduated from HS I got my first job about a mile from where I lived and walked to/from work. Lost 30 lbs in just a few months doing that :)

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

The US government often uses proxies so banning them would wip out millions of potential good members (what's what I used when I first joined DaniWeb)

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

I've heard that several times before -- a glass of wine a day will keep the doctor away, but it only works for small amounts of alcohol. Getting plastered every day is not good for you.