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

I'm closing this thread because what the op wants to do is not legal.

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

>>Assuming it's okay to break all of the existing code that uses iostreams
That would be true of anything that we would like to remove.

>>this removal would only make sense if you already had a provably superior replacement.
There already is a superior replacemenmt -- its the functions in stdio.h. There are a few (very few) things I like about iostreams but for the most part fprintf() is a lot easier to use.

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

If I had to choose something it would be to remove everything in iostream and fstream IMO it is clumbsy and difficult to learn/use.

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

>>I dont have an instructor/teacher or anything im just trying to learn from home, after school.
Good luck. Please don't hesitate to ask questions here.

>>like explain what "cin.ignore()
See this link for some good info about cin

>>does exactly-oh and please dont mix c with c++ i
It means do not mix the two languages in the same program. C++ supports most C functions but it is not considered good programming practice to mix them up. Specifically -- don't use anything found in stdio.h in a c++ program. And don't use anything in conio.h at all because those functions are not standard, which means they may or may not be supported by a compiler.

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

And you probably won't either except maybe some very high-level explainations that don't go into much detail. Microsoft isn't in the business of giving away its company secrets. If you want to know how to use the operating system then there is lots of information about that.

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

But I though DMA is for integers contain in an array only? Characters won't work for DMA....I've tried it before

Huh? I assume DMA means Direct Memory Address. How does that relate to the discussion of this thread ? BTW DMA is not possible with any 32-bit compiler unless writing a kernel-mode device driver.

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

>>_getch_getch
This is a C++ program, not C. So don't use that C function. Use cin.ignore() or cin.get() so that you don't mix C and C++ in the same program. Sure of course getch() works, but its not consistent and you might get lower marks from your instructor for using it.

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

You don't really have to redirect it to the keyboard port but instead stuff the keys in the keyboard buffer. How to do that depends on the operating system.

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

I still have unrealistic expectations of getting back into the pants size I wore 5 years ago. When I'm in a real fantasy mood, I think about getting back into my AF uniforms. (I'm 11 years retired now.)

LOL When I retired from AF in 1985 I put away my uniform and told my wife that I wanted to be buried in it. Well -- I don't think I can get one leg in it any more, they'd have to cut me up a lot :)

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

Its pretty rare for me to post questions here but I came across this one about qsort I can't answer. If I try to sort an array of character strings such as char array[255][20] qsort works ok as expected. But if I declare the array like this qsort fails: char*array[255]

// this is ok
char array[255][20];
int NumStrings = 0;
// fill in the array is not shown here
qsort(array, NumStrings, sizeof(array[0]), compare);

or

// this fails
char* array[255]= {0};
int NumStrings = 0;
// fill in the array is not shown here
qsort(array, NumStrings, sizeof(array[0]), compare);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>doesn't all OS have some kind of clock
Most do, but some embedded systems do not, for example the computers in your car do not have a clock (except, of course, the clock you see). A few years ago when we were all busy making Y2K adjustments to our programs auto manufacturers didn't have to change anything because their computers didn't have clocks. I know of a couple other embedded systems that don't have them either.

Part 2:
Depends. If you know the number of seconds then just add the seconds to the return value of time(). Otherwise, call localtime() to get a pointer to struct tm, change the number of hours, minutes or seconds you want to increment, then call mktime() to normalize the tm structure (make corrections). For example if you want to increment the current time by 9 hours then add 9 to the tm_hours structure member and don't worry if the result is greater than 24 because mktime() will make all necessary adjustments to the date and time.

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

>>how do i allocate it to the size i want
This is c++ so use the new operator to allocate the array m_starts = new int[NumberOfIntegers];

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

First you have to find out how many comma-separated words are in the string. Iterate through the string and count the commans. Then allocate the int array large enough to hold that many integers. After that, go through the string agsin, this time when you find a comma set one of the integers to be the numeric value of where the comma was found.

For example in the string you posted you will need three integers because the string contains three comma-separated words. The first integer will be 0, the second integer 4 and the 3d integer is 9.

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

>>I want to change every comma to a zero?
You can not do that -- the const keyword means the string can not be changed. All you can do is increment the pointer and look at the contents. If you want to change the string then copy it to another char buffer. After copying the string then you can do this to change it

if( *ptr == ',')
    *ptr = '0';

where ptr is a pointer to the copy of the string.

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

just declare another pointer to be the same as the original and increment it until it reaches the end of the string. Along the way count the number of commas etc. You could use the original pointer but its better not to so that you don't destroy the address of the original string.

const char* original = "bad,cold,new";
char *dup = original;
...
...
if( *dup == ',')
{
//   do something
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>You're a man after my own heart.
what makes you think Narue is a man ??? :)

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

Now I wish I had a digital camera so that I could post a couple pictures. When I went to work this morning there were a few places in the country that were really pretty with all the ice/snow covered trees and houses. Picture perfect scenes.

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

line 26: eof() doesn't work like that. Use this instead

while( inFile >> name >> points >> description )
{
   // blabla
}

But that assumes each line contains exactly three words with no embedded spaces. For example it won't read a name such as "John Smith" correctly.

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

>>I do't have a project folder (anyway i do't understand what this mean).
The project folder is the directory where you saved the C or C++ files. I hope you are not dumb enough to put them in the root directory of your computer.

In pure win32 api programs there are no files with standard numbers like ID_FILE_EXIT. You can use any numbers you want because they are only used in your program.

If you are writing an MFC program you will find the declarations in afxres.h which is located in your compiler's include directory. And in MFC its ID_FILE_CLOSE not ID_FILE_EXIT.

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

There are lots of free compilers. But I don't know if any of them have VB-style wizards to generate windows code.

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

I agree, but it isn't free, so that's why I didn't recommend it.

Niek

Oh so you recommended something the OP can't use because its free?

Nick Evan commented: Whoops, sorry 'bout that +3
Jishnu commented: Well said!! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>What can be the reason for this..
Without seeing the program's code we have not idea. The problem could be either in your program of the DLL that you wrote.

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

Yes VC++ 2005 Express is free but it does not contain a code wizard that generates GUI code other than a bare shell with pure win32 api functions. It doesn't let you work with windows like VB does. If you want VB type wizards then Borland C++ builder is probably the best c++ tool.

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

>>declaration of `count' shadows a parameter
You created a variable that has the same name as one of the parameters to that function. Change one of those names to something else.

>>member `contacts' is a private member of class `PIM'
Private members of a class can only be accessed by a member of that class. You are apparently attempting to access it outside the class.

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

Are you writing a windows GUI program? If yes, then you put all those numbers in resource.h file.

>And where i can find all of this?
The resource.h file in your programs project folder

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

line 6: do you have a program on your computer called command.exe ? If not then that line of code will do nothing other than get an error message from the operating system that "command not found".

lines 8 and 10: that loop doesn't work right. You need to combine them like this:

while( file_op.getline(str,5000) )
{
    // compare the strings here to see if this line is the one you are looking for
}

line 13: you can not compare two c-style character arrays like that. Use strcpy() to do that if( strcpy(errorline, str) == 0)

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

Why? you don't need a file just to read those four strings -- hard-code them in your program because they will never change.

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

>>qsort(array[c], length, sizeof(int), compare);
that is incorrect. You are sorting an array of char pointers not an array of integers qsort(array, c, sizeof(char*), compare); Your compare function is also wrong. Why are you converting the char pointers to integers? I thought the strings are words? All you need is this?

int compare(const void* pnum1, const void *pnum2)
{
    return strcmp((char*)pnum1, (char*)pnum2);
}

for (i = 0; i < length; i++)
{
cout << array << endl;
}

wrong there too. length is the number of characters in the original string. What you want here is variable c, which is the number of valid pointers in array

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

Sorry, but its a violation of DaniWeb rules for people to post their email address here.

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

Lets put it this way -- when I put on a Santa suit I don't need any padding :)

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

Is that all there is to the file? What good does it do to list the four types of cards in the file without the quantity that the user holds.

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

>>and compiling c/c++ programs from my mobile phone
Forget it. Mobile phone don't have enough memory or disk space. It needs about 400 meg RAM and about 20 gigs hard drive (depending on the compiler, some more and some less). Even if there were such a thing it would be too slow to be of any value. Get a normal PC or notebook and use that for your programming.

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

My son-in-law loves MAC too -- he does professional graphic design and I suppose that's the best os for that purpose.

bling -- I never heard that term before. Do you mean this?

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

How to read from the file depends on how the file was writte. Post a few lines so we can see what it looks like.

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

>>from my mobile phone
Do you really mean you want to write a progrm for your mobile phone? I know of no compiler that runs on a mobile phone. You will first have to find out what operating system it is running. Is it Microsoft Mobile 5.0 or something else. If its Mobile 5.0 then you will need Microsoft VC++ 2005 Pro edition -- the free Express edition doesn't support writing mobile programs. PocketPC and Smartphone are also Microsoft operating systems and you can get a free compiler from Microsoft for them -- eVC++ 4.0

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

you have too many = symbols -- its == and !=

the loop at lines 18-22 isn't going to work. Move line 20 to after line 13 then delete the rest of the loop at lines 18-22. Another way to code it is like this:

bool done = false;
while( done == false)
{
    for (int buddynum = 0; buddynum < 3; buddynum++)
    {
         cin >> newinput;
         friends[buddynum] = newinput;
    }
    if (mystery[0] == friends[0] || mystery[1] == friends[1])
    {
          cout << "You guessed right!";
          done = true;
    }

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

Thank you for that information. My generation hoarded clock cycles like misers. I've just come back to coding after a long absence and I'm horrified at what looks like sheer carelesness and bloat. It looks like 3 megabytes is the new 16k.

I'm that way too -- I was agast at the bloated code that young programmers write professionally a few years ago. When I asked why not write more efficient code the response was "so what? its user interface and doesn't need to be optimized". Well, they paid dearly for that attitude about a year later when the whole program was so slow that the customer wouldn't accept it.

About Windows 1.0 and MS-DOS 1.0 -- I remember those too. DOS version 1.0 did not have any support for subdirectories and Windows 1.0 was all text based, no graphics or fonts other than the operating systems default font. It ran on top of DOS instead of integrated with it.

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

>> I haven't learned any specific languages yet
Then I'm confused about what it is that you wanted? And why post it in the C++ board if you aren't trying to learn c++ yet?

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

>>not called that in USA
I always call them that but probably because the first time I encountered them was when I went to UK in the 1970s. I've also heard them called turning-circle. We have one about 20 miles from where I live in another town that I pass frequently and you would laugh at the way people drive in them -- or attempt to. Roundabouts are so rare here that most Americans don'w know how to navigate them.

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

Put lines 10 thru 19 in another loop and break out of the loop if the user guessed right.

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

>>What is the value at these lines?
It is extracting the IP address out of the line that was read from server.conf file.

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

you will need to store the pointers that are returned by strtok() in an array of pointers so that the words can be sorted by qsort.

char* array[255] = {0}; // assume max of 255 pointers
...
int c = 0; // arrays start at index 0, not 1
while (token != NULL)
{
    cout << "token " << c << " is " << endl << token << endl;
    array[c] = token;
    token = strtok(NULL,delim);
    c++;
}

Now after that you can use qsort to sort the array of pointers.

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

I don't know what language that was written in -- it looks a little like cobol, but in any event you will have to translate that into c++. Shouldn't be very difficult -- just add the code between start and stop in main() then create functions for all the others.

>> how would I go about initializing the totalCost variable and have it add up correctly for each
Declare totalCost in main() and pass it to the functions.

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

read the line into a std::string object then you can use its find and substr methods to chop off the part of the string you don't want.

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

you need an ifstream object to open the text file, and a string to receive the strings. Both of these are standard c++ classes in <fstream> and <string> header files. There are hundreds, if not thousands, of examples you can follow to write your program so I am not going to repeat them here. Basically you need to (1) read a line using getline function then (2) compare it to the string you are looing for using the == comparison operator.

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

moved

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

Did you read the Read Me threads at the top of this c++ board? If not then you should because there is lots of helpful information -- and without popups.

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

>>what is the best way to sort all strings in arrPP
Declare them all in one big array and in sorted order then you won't have to worry about that.

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

I think you need to get a newer compiler that supports current c++. Dev-C++ is free and used by many people. Also VC++ 2005 Express is free and actually a better compiler, but a little more difficult to learn how to use. There are several other compilers too.