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

line 29: open() wants a const char* for the filename and you passed a std::string object. I'm supprised your compiler did not object and spew out some nasty error messages. It should be this: in.open(inFile.c_str()); line 39: unnecessary -- if open() failed the stream can not be closed.

line 73: input file was never opened so lines 73-82 will probably never get executed.

lines 75-80 should not be inside the while loop beginning at line 73 because total sales will get counted several times. Move that for loop outside and below the while loop.

Actually, in sumArray() you don't need that double array at all because you don't do anything with it. A better solution is to read the array into memory once in main() then pass the array to sumArray() function. Just add another parameter to sumArray().

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

endl puts '\n' in the file then causes the output stream to be flushed to disk. The interpretation of '\n' depends on the operating system and whether the output file was opened in text mode or binary mode.

Are you attempting write the file out on *nix operating system then transfer it to a MS-Windows where you read it with Notepad or some other text editor ? That will cause the behavior you described. Otherwise I have never had that problem.

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

>>are void and int only 2 declarations for main

void is never ever a valid declaration for main(). ALWAYS declare it as returning int.

add this between lines 2 and 3 of your program float square ( float x); It will tell your compiler about that function.

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

>>are this correct soultion
No. lines 21-28 are incorrect because lines 26 and 27 will never get executed and the while statement at line 21 is wrong.

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

forget about VC++ 6.0 -- its too old and does not meet c++ standard very well, and sometimes not at all. Get VC++ 2005 Express (free) instead.

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

start here

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

I just came across this interesting article in our local electric coop newsletter, and found an online source here.

Moses and the people were in the desert, but what was he going to do
with them? They had to be fed, and feeding 2 or 3 million people
requires a lot of food. According to the Quartermaster General in
the Army, it is reported that Moses would have to have had 1500 tons of food each day.

Do you know that to bring that much food each day, two freight
trains, each a mile long, would be required! Besides you must remember, they were out in the desert, so they would have to have firewood to use in cooking the food. This would take 4000 tons of wood and a few more freight trains, each a mile long, just for one day. And just think, they were forty years in transit.

And oh yes! They would have to have water. If they only had enough
to drink and wash a few dishes, it would take 11,000,000 gallons each
day, and a freight train with tank cars, 1800 miles long, just to bring
water!

And then another thing! They had to get across the Red Sea at
night. (They did?) Now, if they went on a narrow path, double file, the
line would be 800 miles long and would require 35 days and nights to get through. So, There …

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

might have to write a windows device driver. you can download the windows DDK from Microsoft web site -- just search for it.

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

VC++ 2005 Express
Dev-C++
Turbo C++

just to name a few :)

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

>>how do i use the data for just the year only not the whole input?

convert the last four characters of the string to an integer. There are several ways to do that but the simplest is to call atol()

std::string date = "07/05/2007";
int year = atol(&data.c_str()[6]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course you can crate GUI programs with c++. The entire MS-Windows api is written in C and C++. Also I bet the *nix GUI is also C/C++.

>> can now say i am a c++ programmer
Probably. Have you learned everything there is to learn? Definitely not. You will never stop learning.


>>will i need a certification to get a job
No, and certs are rarly even necessary. Into jobs only require bachelor's degree of equivalent experience. If you are really good at it you might want to consider getting a master's degree.

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

I like dogs but I also like cats. When I was a kid living on a farm we had about 25 cats at the same time -- of course they were all out-door cats that lived in the barns and corn cribs. They loved milk-time -- when I milked our cow I had to give them all a squirt or two of milk. We never had a rat or mouse problem.

Also had a pet white rabbit that lived around the yard a couple years eating corn that dropped out of the corn cribs, as well as other stuff. He came up missing and after a few months I went to our neighbors for some other reason when he just happened to mention that he saw a large white rabbit that he shot and ate. That was my rabbit! but I never told him.

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

then wat should i do....

fix it. its your program, not mine. I don't know what you want it to do.

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

>>I'm not interested in even risking downloading a non-portable file format which is prone to all sorts of virus infections

Absolutely agree with that -- *.doc files have been known to contains viruses, worms and other kinds of animals. Kg: save your program as *.c and either post it or attach it if its too big to post.

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

>>a simple c code which will run when ever we plug in the usb drive
:icon_lol: :icon_lol: :icon_lol: :icon_lol: :icon_lol: :icon_lol: :icon_lol: :icon_lol: :icon_lol:

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

>>can u tell me wats the problem

First you need to learn how to format your program better. What you posted is absolutely terrible! Take the time to use the space-bar on your keyboard and make your program easy to read. You will probably get a better grade for it too :)

Look at the last two lines! They are just nonsense, unless of course there is more code that you did not post.

why use dynamic allocations for variable GameBoard? Its size never changes so why not just hard-code it an array of 9. Don't use dynamic allocation unless you absolutely have to such as when the size is not known until runtime or when the object is too big to put on the stack.

Otherwise, I have no idea what's wrong with your program.

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

check out this site. If you are using ancient Turbo C++ I don't think it can access either PS2 or USB mouse ports because you will need a MS-DOS device driver which pre-dates both port types.

If you are using the newest version of Turbo C++ then you can use win32 api windows program mouse events.

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

Post code please.

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

OMG! what did you do in lines 10 thru 35? Delete all that crap and use arrays of structures as your assignment told you to do and as I explained in my previous post.

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

This and this are probably the places to start. But you may need the services of a lawyer to get specific information about the food you want to import.

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

after line 65 you should clear the prson array by setting everything to 0 -- you can use memset() to do that very quickly

memset(prson,0, sizeof(prson));

to search for a given person you will, of course, first have to ask for the person's first and last names. Then create a loop and look at each prson object to compare last and first names in the structure with what you entered. you can use strcmp() to do that. In this code snippet assume i is the loop counter, lname is the last name you entered from the keyboard and fname is the first name you entered from the keyboard. Since strcmp() returns 0 when the two strings are identical you can test like this:

if( strcmp(lname,prson[i].lname) == 0 && strcmp(fname,prson[i].fname) == 0)
{
   // blabla
}

To delete an element from the array just memset() it to 0 again

memset(&prson[i], 0, sizeof(struct person));

Use of gets(): such as in line 31. Use fgets() instead because gets() will allow you to enter more keys than the buffer can hold. For example if you enter 30 character for last name then the program will crash because gets() will scribble all over memory with the extra characters. fgets() does not have that problem because you tell it the maximum number of characters that the buffer will hold.

Line 30: you are using variable i before it has been initialized with anything. All it contains at that point is some random …

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

I rarely turn my computer off at home, but I normally do turn my monitor off when I'm not using it. Not because I want to save planet earth but just being mindful of my electric bill, although I doubt it really makes much difference.

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

lines 16 and 17 need to be reversed because they are in the wrong order. You have to display the question on the screen before you expect someone to enter the answer on the keyboard.

who gave you that code snippet? I sure hope it was not your instructor, because if it was you are in for a lot of problems. Line 18 is not the correct way to write that kind of loop. For the first problem it should be like this:

while( infile >> letter )
{

}

>>(Hint: you have to use continue statement in your solution )
Ridiculous -- no you don't. That problem can be easily solved without using the continue or break statements. All you have to do inside that loop is check if letter is the correct character and increment the counter if it is.

And the second problem is just as stupid as the first. My thoughts: you have an idot for a teacher!

iamthwee commented: I wish I had an iDot for a teacher, although I have a iPod? +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Argg. The only thing I even post in is the coffee house because I don't know anything about computers or anything. I.

Of course you do know something about computers! If you don't then how in the world are you posting on DaniWeb :-O

Take a look at the Tech Talk board -- you may supprise yourself that you might know the answer to a few of the questions there. Read some of the problems and see if you can figure some of them out. Before you know it you will become as good as most other posters there, and start getting rep points for at least trying.

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

I could care less what my African name is -- I'm not from Africa so it doesn't matter.

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

The major problem you fase is the operating system you plan to use. MS-Windows and *nix will not permit programs to access the ports directly like that program you posted. Only MS-DOS will permit it.

Search some of these google links to see it they contain anything useful to you.

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

Then post your question(s) on their forums. You will probably get faster response there.

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

>>“Write a C++ program (use multi-dimensional arrays) that uses an array structures

Where have you declared the structure ? and where did you declare the array? You need a structure something like this:

struct company
{
    std::string company_name;
    long Quarter_sales[4];
    long Total_annual_sales;
    long Average_quarterly_salesl
};

lines 45 and 46: Divisions and Quarters should be combined into one structure something similar to what I posted above.

lines 148-155: delete those variables. The calculations should be stored in the structure members not in simple individual int objects.

lines 193-199: That should be sorting the array of the structures similar to what I posted above. Sorting an array that only contains the averages will not give you what you want because it doesn't keep the other information in the same order. Putting everything in a structure similar to what I posted previously and sorting that array solves that problem very easily.

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

you have to use os-specific functions. What compiler and what operating system ?

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

delete lines 7 thru 11 because they are invalid statements. change line 6 like this

char cStudent[5][10] = {0};

Move line 18 after line 4. The brace goes immediately after the function declaration (unless you use ancient K&R original style, which you are not).

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

read this FAQ and read their tutorial

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

MSDN is free at www.microsoft.com and can not be downloaded. If you need a local version you have to buy it for about a thousand $$$.

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

why are you reading the file? All you have to do is call fseek() to move the file pointer to the end of the file then call ftell() to get the file size. Another way is call fstat() which returns the file size in a structure.

>>How much size of bytes or KBs or MBs are permitted for my Linux C program on a 64 bit processor
To my knowledge its limited only by memory.

You don't want to read that large files all into memory at one time anyway because the system will just swap the majority of it to disk and you have accomplished nothing. Its better to design your program so that you only need to read small chunks at a time, such as one record at a time.

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

Didn't you know? It's illegal in his house to invade any nation.

Yes that is correct. Its illegal (or against USA prior doctrins) for USA to invade any nation as first strike. Iraq did nothing to us, they were not the cause of 9/11 or Pearl Harbor either.

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

That is wrong anyway. Are you using VC++ 2005 compiler ? If so, then to add a library to the project press Alt + F7 keys and the Property Pages dialog box will appear. Expand Configuration Properties, then expand Linker, select the Input category under Linker. Then on the right side of the window add the library in the Additional Dependencies control.

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

If we were going to impeach Bush it should have been done 5 years ago when he first illegally invaded another sovern nation. And should have impeached the entire Congress for letting he do it. Too late now. The next President will have a huge job straightening that mess out.

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

set all the time fields in the structure to 0 then convert. Or, alternatively, you could call modf() to split the double into integer and fractional parts, then compare only the integer parts (the fractional part contains the time and integer part is the date).

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

Could u plz give a little example code of this kind of bug?

change p from this BulkData * p = malloc(sizeof(BulkData)); to this AnotherStruct * p = malloc(sizeof(BulkData)); Notice the bug that is now introduced in the above line.

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

convert them to doubles using SystemTimeToVariantTime() then its trivel to compare them.

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

1. its not necessary to prototype main() as you did in line 8 because main() is defined by c standards and can not be called anywhere else in your program.

2. delete the unnecessary brace on line 79 because it serves no useful purpose.

3. line 76
>>int DrinkArray[0] = 0;

Illegal -- array must have a size greater than 0

4. lines 76, 77 and 78. Arrays are initialized like this:

int DrinkArray[2] = {0};

5. same lines as above. duplicat object declaration. delete lines 77 and 78 to correct this.

6. >> return main;
illegal syntax. delete that line.

I'm not going to go thrugh the rest of the code. Make corrections as suggested, recompile then post corrected code with more questions.

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

you will probably want to create a structure to hold the information for each student, something like this:

struct student
{
   char name[80];
   int grades[10];
}

Now you will have to declare an array of 5 of those structures. Then create a loop that prompts for student name and the grades, then add this information to the ith array element structure.

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

Read this discussion. Rep is no longer valid in Coffee House, which includes Geek's Lounge.

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

I tried defineing it in Tools --> Compiler Options, but it didn't work.

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

line 28 of the first program is wrong. compare it to line 26 of the second program.

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

maybe you need to get the newest version of that compiler ??? I don't use it, so don't know.

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

They both allocate the same amount of bytes. The difference is that the first method is safer because at some future time you can change what p points to without having to change that malloc() line of code. Its just a way of making a programmer's life a little easier and causes fewer bugs to get introduced into the program.

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

>>why do these two programs have different outputs
Don't know either. What are the two outputs?

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

maybe this ?

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

Compiled without errors/warnings with my compiler -- VC++ 2005 Express as both a C and a C++ program. What compiler are you using ? Does your compiler complain about the below ?

char* foo1()
{
    return (char *)malloc(255);
}

int foo(void **vpSec00)
{
    
    *vpSec00 = foo1();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I think malloc allocates 8 bytes of unused space with this, beacuse size of *p is 8 bytes in my system

No it isn't. The asterisk tells sizeof operator to evaluate the size of the object to which the pointer points and not the size of a pointer itself. In your example it will get sizeof(BulkData)