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

Its pretty simple, really. Just create an array and read each line into its own element of the array. You will need a loop to read the file until eof() and an int counter to keep track of the line number read so that it will know which row to use in the array.

There are a couple ways to implement this: and here is probably the easiest (and best) approach.
Since this is c++ thread then use <vector> as the array and <string> to hold the text of each line. Create a std::ifstream to open the file and call getline() to read each line.

Look through the C++ Code Snippets and you will probably find example programs that read files into arrays.

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

*.cpp files may, not required to contain main(). A program can be comprised of many, if not hundreds, of *.cpp file(s). GUI programs written for MS-Windows do not have a main() at all -- instead they have a WinMain().

When you write a c++ console program, it can contain as many *.cpp files as you want it to have. But only one, and only one, of them can contain a main() function. Actually, that isn't completly accurate either because the main() can be in a *.c (a C program unit, not c++). Many programs consist of both *.c and *.cpp files.

Header files normally (except c++ templates) consist of only c++ classes, structures and defines because they can be included in all the *.c and *.cpp files within the project(s). The implementation code is normally contained in *.c and *.cpp files.

>>Are you saying that individual custom GUI classes CAN"T be -or shouldn't be spun off into external files at all?
Not sure what you mean by that. GUI classes, just like all other c++ classes, declarations should be in *.h files and implementation code in *.cpp file. Many companies require that a *.cpp and *.h file is limited to only one c++ class and correcponsing *.cpp implentation file. So if the program consists of two unrelated c++ classes then each would be in its own *.cpp and *.h file. The *.cpp files are conpiled separately and linked together at link time along with other libraries.

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

Unless you are writing c++ templates don't put executable class implementation code in *.h files -- it goes in *.cpp file.

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

>> for (j=1;j&lt;=n;j++)

I think you misquoted the code (lines 19 and 20) because that is just so much nonsense. Proofread the code you have to make sure you did not make typing errors. If its really like that in the book then go to the publishers web site to see if they have a list of book corrections or electronic copy of the code, which sometimes has corrected code.

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

did you read this ? Or research these google links ?

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

what operating system ?

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

>>recursive implementation of depth first search
read this

>> is it possible to code any problem with recursion without using global variable
yes, pass them as a function parameter

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

sort() does in-memory sort -- what you need is a file sort program. Or better yet write a file sort-merge function and add it to your program to preprocess the file. That way you can do away with that fork pipe and exec function calls.

you might check the boost libraries to see if it contains anything usefule.

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

tm struct does not contain milliseconds. But if you don't care about milliseconds then tm will work in all platforms and compilers because it is in standard C library.

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

Are you blind, senile, have demeinita, or maybe older than I am? I have already told you TWICE what the problem is with that second program. And this is the third time you have posted that same code. Now, go back and re-read the responses to your previous threads. I'm going to put you on my ignore list if you don't start reading the responses to your other threads. I would hate to see you get banned just because you fail to read (a few more screw-ups away from it.)

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

I don't have a problem any more prettying-up people's code. But I'll be darned if I'm going to fix all those color and font tags that are in some people's posts. The A button in the upper-left corner of he message box only works when there are matching close tags for each open tag. I would like Dani to have a script that forbits color and font tags, or just quietly remove them when posted.

iamthwee commented: Ever heard of regex, use it to create a generic expression to remove font tags etc? -2
~s.o.s~ commented: I am sure AD has seen more books than the regexes you have crafted Iamthwee... +25
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A nice PM does indeed work wonders -- at least it did for one member. Some people, like him, just didn't understand how code tags worked. The use of warnings and infractures would probably have been counterproductive. Now his most recent post this morning contains correct code tags.

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

Can someone help im suppose to write a family of overloaded functions called equal(), which take two arguments of the same type, returning 1 if the arguments are equal, and 0 otherwise. This is what i have that refuses to compile.

What question(s) do you have about the code you posed? People normally don't post code just for the hell of it.

Can someone please tell me why this one will not compile

I already did -- here.

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

. Looks like the mods are at least trying now. Now why didn't they do this sooner? :)

we have -- maybe you just were not paying attention.

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

If you have an int array of all seats, initialize the elements with 0. When someone reserves a seat change it to 1. When someone shows up and claims the seat change it to 2.

Then to show all the reserved seats iterate through the array and print the ones whose value is 1. For example

for(int i = 0; i < MaxSeats; i++)
{
     if (seats[i] == 1 )  // a reserved seat
          printf("Seat %d is reserved.\n", i);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It will compile if you include <iostream>

line 31 of your first post is syntax error. you can't use for alone like that. maybe you meant an infinite loop like this: for (;;) line 38 is a do-nothing statement and may as well be deleted. Did you intend to call a function here?

line 47 of second program: remove the semicolon at the end of the line. This is a gottya for many (most) programmers, even old experienced ones.

line 63: variable month has not been previously initialized and contains some random value.

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

>>I'm trying to write 2 codes in C++, but i'm having major problems
what exactly are the major problems ?

>>This is what i have so far:
That's nice. Now what do you want us to do? Or what question(s) do you have?

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

>>So I don't see what the problem is?
The problem is that I don't want to manually space out all those lines.

But I found a happy solution Here is an on-line code beautifier that seems to do the trick quickly and effortlessly. Just past the code into the edit box and press Submit button.

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

>>The moderators instead should be more diligent, and take the time to not only add code tags but also properly indent it for others to read

Remember we all do this for free -- none of the mods are paid employees. I normally don't add code tags to code that has not been indented. I first hit the Edit button then look at the code. If its intented then I add the code tags, otherwise I see no point in using code tags. I think its asking to much of us to reformat the code according to OUR formatting standards, and we all probably have different code standards. Then I can see somebody suggesting to Dani that we need standard code formatting rules. No thanks.

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

But can't you just remove formatting with the top-left button in the edit window that looks like a slanted 'A'?

It did nothing to the following example I cut out of another earlier post.

from datetime import date

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

>>(MSVC++ throws a warning about pointer truncation
VC++ 2005 has a switch in properties to turn off 64-bit warnings

Properties --> Configuration Properties --> C/C++ --> General, "Detect 64-Bit Portability Issues". Set it to NO and you won't get that warning. In 64-bit compilers sizeof(any pointer) != sizeof(long)

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

>>why is it 32

Look at any standard ASCII chart and you will see that the letter 'A' = 65 and 'a' = 97. 32 is the difference between them. Subtract 32 from any lower-case letter and you will get the upper-case letter.

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

non-static C++ class code can not be called from VB so you have to write the DLL as C code or as static methods in C++. In both cases the functions have to be exported when compiling the DLL.

In VB code just predeclare the functions as you would any other DLL function such as win32 api functions. I don't recall the exact syntax but there must be hundreds of examples.

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

>>And why would they when there are plenty of lap-dogs to clean up after them

:angry: I resent being called a "lap dog"

>>Unless you put some serious inconvenience in the way, they're just not going to learn

Learn what? how to use code tags? Yes, I've given out a couple warnings about it, but I don't think it was worth the effort. I would rather just quietly add code tags (or correct them) rather than lose a DaniWeb member. Failure to use code tags is not really all that big a deal. What IS a big deal are people who use font and/or color tags on every line of their code. I don't bother to correct them -- don't have the ambition to edit all those lines.

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

why don't you just download the free DICOM viewer from here? There's also a discussion group where you can ask them specific questions.

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

go to www.amazon.com and do search for those subjects -- entire books have been written about them so its unlikely we can do them justice here.

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

>>if ( islower(str)) >= 'a' && str <= 'z') // If lowercase letter

wrong syntax. Should be this:


#include <ctype.h> // add this line somewhere after stdafx.h

for (unsigned int i = 0; i < strlen(str); i += 2) 
{ 
       if ( islower(str[i])) // If lowercase letter 
               str[i] = toupper(str[i]); // change to uppercase 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I'm stumped again, is it my compiler?
Not your compiler -- its your code. Post your code because I can't see your computer's screen from where I am sitting.

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

>>p==&i;
That is a logical expression, not an assignment. Its asking if the address stored in pointer p is the same as the address of i.

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

>>Let say I belive you.
Ok, Ok you caught me. I lied :twisted:

>>I don't know how to get cout to print the address of a pointer
I see from my previous post that its actually easier to print the address using cout than it is with printf(). :)

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

In the second program you should really use islower() macro to check if the character is lower-case. Then use toupper() to convert from lower-case to upper-case, like this:

if( islower(str[i]))
   str[i] = toupper(str[i]);

Otherwise, that program works ok for me. :)

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

line 18 is executed before line 19 so when line 18 is executed ptr2 is uninitialized. You must initialize pointers and other objects before (not after) attempting to use them.

>> I thought (just like you) that it will be random but when I compile it sais 0

When I execute your program I get this output, after getting an error message

3200 3200 0012FF40 CCCCCCCC
0012FF40 3200 0012FF40
0012FF40 3201 3201

The value of 0 may be random -- whatever is at the memory location at the time. Apparently, 0 is at that memory location.

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

which line ? On line 18 the value of ptr2 is random because it is uninitialized. Line 22 is also random because it is deferencing the integer located at the address of the address, which also has not been initialized and could possibly crash the program.

I don't know how to get cout to print the address of a pointer -- printf() uses "%p" but don't know about cout.

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

>> try to compile that program to see the results
your compiler told you the results didn't it? The result was that the compiler could not compile it due to syntax errors.

>> I cant because "Clifton" is to long for that array

No big deal -- just increase the array size. Even if you got it to work as in your original code (one character at a time) it don't work right because the string dones not contain the null terminating byte.

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

Maybe -- depends on what api functions you use. When unsure what version of the os a function supports, look it up in MSDN and it will tell you. There are many functions that are either unsupported on older versions of Windows or does not exist at all. For example, UNICODE is not supported in Win95/98 so if you compiled your program for UNICODE it will not run on either of those versions of MS-Windows.

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

initialize the arrays like this:

char name1[ arraySize ] = "Kenneth";
char name2[7] = "Clifton";
char name3[] = "Suzanne";
char name4[10] = "Elizabeth";

Note that you might get buffer overflow errors -- I'll leave that up to you to fix.

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

Welcome to DaniWeb Gorden.


>>Where can i learn how to program
depends on the language you want to start learning. Look in the Software Development boards and you will find lots of hints and links in the Read Me posts at the top of each board.

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

you need to add break statements at the end of each case statement so that the program does not execute the lines for the next case statements.

delete line 60 -- never ever for any reason call main() from anywhere within your program. That function is intended to be called only from the program's startup code.

>> it will not show the reserved seats
I would create an array of ints that represent each seat in the plain and the status of that seat, such as unassigned, assigned, reserved, etc. That makes it easy to know which seats have been reserved.

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

Here is a popular tutorial. win32 api is C, not C++. You can create c++ programs that call win32 api but it isn't necessary. MFC and wxWidgets are two c++ gui libraries. wxWidgets is free and works with most compilers and operating systems. MFC is not free and restricted to MS-Windows.

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

line 33: function prototypes should be placed above and outside any other functions (about line 5)

requirement 1) delete the prompt for experiement data (lines 46 through 52). This option should only save the linked list of structures what was created by requirement 2) (follows)

Requirement 2) prompt for the experiement number and associated value, then add a new node to a linked list with this information. If you enter an experiement number that already exists then just overwrite the structure with the new value.

Requirement 3) - iterate through the linked list and computer the min and max values then print them on the screen.

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

moved

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

Can't you use loops and division and multiplication to get the square root ? For example, the square root of 16 can be found by trial-and-error multiplying 1*1, then 2*2, then 3*3, then 4*4 until you get a number that is close to the original number.

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

use one star for each dimension, like this: int ***a; Now, in C programs, call malloc() to allocate each dimension. This will require two loops for the second and third dimensions.

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

See this article And here are some google links you might also want to read. Looks like some of them have example code.

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

Have fun and study hard. Will be expecting a report of the fun things you did during your vacation. :)

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

int space [].

That syntax is ok when declared as a parameter to a function, but not when declaring an object within the body of a function. I may (probably) misinterpreted your post.

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

int space [] is in effect the same as int *space, you can use one instead of another.

Sorry, but the two are not interchangeable. int space [] causes illegal syntax error message (VC++ 2005 Express compiler.). Unless that is something new in C99 standards, which very few compilers support yet.

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

Thanks -- it does clear up the problem. I just hadn't bothered to read it right below the Signature edit box :icon_redface:

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

what you are doing is attempting to print the binary value of the number. It has to be converted to ASCII before it can be printed. If you look at an ascii chart you will see that the ascii value for '0' is 48 decimal, or 30H. So if you want to print the 0 digit you have to add 48 to make it printable on the screen.

using a loop your program needs to split the value of sum up into its individual digits and add 30H to the digit before printing it.

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

Do you realize they don't work in signatures? I just saw it too, the most recent post anupam_smart, here