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

2 -- h() and g().

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

>> Does anyone have any suggestions as to how I could better this code.

Yes -- use code tags. Your code is too hard to read to make any useful comments.

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

you can use std::string's find method to locate the spaces

int main()
{
std::string line = "Hello World";
std::string word;
int pos;
while( line != "")
{
	pos = line.find(' ');
	if(pos >= 0)
	{
		word = line.substr(0,pos);
		line = line.substr(pos+1);
	}
	else
	{
		word = line;
		line = "";
	}

   // now word is just one word
   cout << word << endl;
}

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

I repeat my previos comment -- you did not ask a question that can be answered. you should probably get on the gcc web site and find out what those compiler flags mean before you attempt to use them. I suspect (a guess??) -ansii flag tells the compiler to use strict ansii standards when compiling your program. If your program contains any non-ansii code the compiler will complain. Beyond that, its anybody's guess what is wrong because you did not post any code.

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

>> would like to test that api program in c, not vc.

you won't test it with Turbo C. See my previous post (I changed it so you might have to re-read it)

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

You are also ancient dragon.
Are you good?
It is just joke.
Please guide me.

Sorry -- I couldn't resist the laughter.

you cannot use TC because it is too old and does not know about long file names -- file names that are longer than 8 characters followed by a perios and 3 characters for the extension. That is the ancient MS-DOS format. The files in the download you are trying to compile have long filenames.

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

now what the he!! kind of question is that? Do you say this to your auto mechanic My car is broke, will you fix it :evil:

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

could u tell me the problems in
defining a 3D double array. that is
double a[1000][1000][1000];

Why do new programmers think their computers have an infinite amount of memory? That array takes 8,000,000,000 or about 8 Gig of RAM! Redesign your program or use a file.

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

Don't laugh at me.
I am using turbo c compiler. It is an ancient software.
I also try to use Borland 5.5. But that gives many error when I compile .c file.

:cheesy: :cheesy: :cheesy: :cheesy: :cheesy: :cheesy: :cheesy:

trash those old ancient compilers! you can get pretty good free compilers, such as the Express I mentioned previously or Dev-C++ from www.bloodshed.net.

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

What compiler are you using? your program contains a whole bunch of errors that your compiler should have complained about. You have to fix up those problems before you can run the program. Just because the compiler may have produced an executable program doesn't mean that program will run, especially if there were compiler errors. The modern compilers I know about do not produce an executable when there are errors.

Once you get it to compile with no errors, there are other more suttle errors, such as using variables before they are initialized. See function main() which uses pointer keeptrack without initialzing it, and this will cause a big crash in function displayCalendar().

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

What compiler are you using? If you use Microsoft Visual C++ 2005 Express, the download includes project files.

If that is your compiler, then the compiler will spew out a whole bunch of warnings about using deprecated C functions. you can disable the warning with a pragma. put this at the top of link-includes.h. Otherwise everyting compiled and linked ok for me using VC Express compiler.

#pragma warning(disable: 4996)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

.h files are includes in .c files

// myfile.c
//
#include "myheader.h"
// rest of c program here

Then run your compiler against all the *.c files. It will create *.obj files which can be used by the linker to create the executable file.

Beyone that, how to do all the above depends on the compiler and operating system you are using.

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

The insertion operator >> stops at the first space. use getline() to get a whole sentence.

getline(cin,word);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

iterate through each character of the string and use the macro toupper() found in ctype.h to convert the characters to upper case.

char c = 'a';
c = toupper(c);
// now c will == 'A'
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could try to use Google

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

which line is in bold ? they all look bold to me. how about adding some comments that point to the line

... <<< this line is the error

I think its better to use code tags when posting code, not php tags.

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

If isalpha() failes it does not mean that the character is a numeric digit, it could be anything else too. If you want to check for numeric digits then use isdigit(). And both only check one character, so if you have a whole string then you must check each character individually.

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

>>Please Help Me with my c++ homework

Tanslated: Please do my homework because I'm just too busy (or lazy) to do it myself.

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

>>Anything that evaluates to a null pointer constant

What I really meant was that since NULL is a macro you can redefine it as anything you want it to be

#if defined(NULL)
#undef NULL
#define NULL "Hello World"
#endif

I haven't seen anyone do that, but I suppose its possible. And that is why Bjarne Stroustrup said he doesn't use that macro, he always uses 0 instead, as shown in my post. http://public.research.att.com/~bs/bs_faq2.html

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

>>I need to change the definition of DisplayBuffer to allow values to be assigned to it.

you don't have to make it a pointer as I posted, just copy whatever string you want into it.

char DisplayBuffer[255];

strcpy(DisplayBuffer,"Hello World");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why are you using memcpy()? use strcpy() and you won't have to worry about null-terminating the string.

void main()
{
const char sendText[] = "Hi";
buffersize = strlen( sendText );
buffer = (unsigned char*)malloc( buffersize + 1 );
strcpy( buffer, sendText);

}

>>'=' : 'unsigned char ' differs in levels of indirection from 'void *'

you should not use NULL. The macro NULL can be defined as anything, and some compilers define it as (void *)0. I believe C++ now requires it to be just 0.

buffer[buffersize] = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

have you tried this? I guess you already know that you will have to allocate memory for that buffer before using it -- yes??

char*  DisplayBuffer;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of other descriptions for arrays. Yes, your program uses arrays. post what you are typing for each of the names.

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

>> char names[10];
>>scanf("%s",n);}

the above is incorrect.
1. you need and array of 10 strings. What you posted is one array of 10 characters.
you have to pass a character array, not an integer

char names[10][10];
for(n=0;n<10;n++){
    scanf("%s",names[n]);}
}

One major problem with scanf() is that you can type as many characters into the string as you want and scanf() will simply overwrite your buffer with no bounds checking. This will probably cause your program to crash. fgets() is better than scanf() because fgets() you can tell it how many caracters to accept.

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

Just use google

Use loops to iterate through each dimension of the matrices. Doing other matrix math is about as simple as below. Note: I didn't compile or test this code.

// add 2 matrices
int array1[2][2] = {{1,2},{2,3}};
int array2[2][2] = {{3,4},{4,5}};
int array3[2][2];

for(int i = 0; i < 2; i++)
{
  for(int j = 0; j < 2; j++)
  {
     array3[i][j] = array1[i][j] + array2[i][j]);
  }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

concantinating two std::string objects is pretty easy -- almost the same syntax as adding two integers together.

std::string s1 = "Hello ";
std::string s2 = "World";

// now concantinate s2 to the end of s1
s1 += s2;

// or if you prefer
s1 = s1 + s2;

>>• Implement multiple string and c-string class functions.
I don't know what that means either -- there must be parts of the instructions that you didn't post.

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

>>Please help!!!

Please help do what?? do you want us to do your assignment (homework)? something you don't understand about it?

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

As he says that it worked with Visual Studio 6.0, most probably some form of that file should be in his computer already. Good to have the latest version of the PSDK though. Especially with the brand new compiler. :D

Visual Studio 6.0 is shipped with those dlls -- he doesn't need the Windows SDK for that.

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

If you want it ported to MS-Access or Oracle you will have to use their database engine to import the file into the database tables. Each database has its own unique file formats so the safest way to do it is to use the appropriate database engine. And some cost thousands of $$$$$$$. Some are relatively cheap or even free (like MySql)

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

And you will probably also have to download the Windows SDK free from Microsoft.

That will not be the only porting problem. VC++ 2005 Express is a lot more c++ IOS standards compliant than VC++ 6.0, so that will be a little bit of recoding required.

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

>>Whenever I attempt to run this program,

Since you are new -- you did not run this program, but you compiled this program". If you are going to learn programming then you need to also learn programming jargon. "run a program" means the program is already compiled and you can execute it, just like you execute most other programs on your computer.

And for future reference when you post questions and code it is very helpful to everyone if you would also indicate the compiler you used, its version (if known) and the operating system you are using.

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

you will want to use floats --

float value1, value2, answer;

value1 = 1
value2 = 2
// divide operator
answer = value1 / value2;
//
// multipication operator
answer = value1 * value2;

// etc

as for the switch -- I already posted a brief example. your text book probably has a more thorough explaination.

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

lean to crawl before you try to walk and run. Before you even think about game programming take a year or so (depending on how fast you learn and how much time you are willing to spend at it) to learn the language. If you already bought an introduction to C or C++ language, start on page 1 and read thoroughly, doing all the questions at the end of the chapters. There are lots of books at the book store or online at www.amazon.com -- make sure the one you get is Introduction to ... -- and NOT "C++ for Dummies" !

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

Don't get too overwhelmed -- this is just a simple console program. Begin with the simplest program you can think of then gradually add more code to make it do what the requirements state. Don't attempt to implement everything all at one time. Here are a couple hints:

select from a numbered list of operations
This is a menu to select what operation to perform

1.  Add
2.  Subtract
3.  Divide
4.  Multiply

Then get user input to select one of the above menu items. Then code a switch statement to perform the desired operation

switch(Selection)
{
  case '1':
     // Add -- add the two numbers
     break;
  // etc. etc
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

linked lists can be pretty confusion topic. you might want to study about them in more depth. Read one or more of the many tutorials you will find. Your text book should also have a chapter or two about them.

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

What compiler did you use??? I compiled it with Dev-C++ and below is the output. Is that what you expect? The only thing I changed was replace <iostream.h> with <iostream> because iostream.h is obsolete (deprecated, I think that's how its spelled)

[edit]And changed const dim = 48; to const int dim = 48; [/edit]

D:\tmp\IUCUNN_08_mar>Project1
Training...
Initiating Layer 1... Done.
Initiating Layer 2... Done.
Initiating Layer 3... Done.

epochs: 0

epochs: 1

epochs: 2

epochs: 3

epochs: 4

epochs: 5

epochs: 6

epochs: 7

epochs: 8

epochs: 9
Training done!
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I asked when generally this occurs..

And I answered it.

you can zip it up and attach it to your post. Better still -- create a very small program that contains the offending line of code to see if you can duplicate the problem. If you can and still don't know what is wrong then post that example program.

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

Hi!

I'm new in C++, but perhaps this is a general problem, not C++ exclusive.

This is printed in my console, "-1.#IND", when using a printf, when this occurs?

thanks

might be that you passed printf() an uninitialized variable, but since I forgot my crystle ball today nor am I a mind reader, you will have to post your program.

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

>>file handling is one way I cannot go abt doing this

The only other way I know of is to redirect the input and output on the command line.

c:> myprogram < infile.in > outfile.out

That will redirect the file's contents to stdin just as if you typed the information on the keyboard, and redirect stdout to a file instead of displaying it on a console screen.

But I don't know why you can't just use FILE and associated C file handline functions to read the input file and write the output file.

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

>>C is a small language, and is best served by a small book

but it has an abnormally huge price! Just because K&R was written by the language's authors doesn't mean it is any better than books twice as big and half the price. That K&R book with white cover is grossly overrated.

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

I will agree that when writing c++ program use c++ stream classes and not resort to C. There are many benefits to using streams than just a few micro-nanoseconds speed. I wouldn't have even posted in this thread had I not read Narue's test and tried it on my own computer. I haven't used STLPort or boost libraries, so no comment there.

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

ugh, nevermind apparently windows doesn't support dup'ing

yes it does -- for redirecting stdout or stderr to a file. You can't redirect it like that to a MS-Windows GUI control, such as an edit control. And I don't think you can do that under *nix X11 controls either.

But I know what you want to do can be done -- I've seen it, but not sure how to do it either. Maybe pipes is the way to go.

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

I just ran Narue's test on my XP, 2.41 GHz AMD Processor, 1 Gig RAM and pretty fast video card.

printf: 9.75
cout: 10.359

compiled with Visual C++ 2005 Express editiion in release mode. One problem with such as test is variance in speed of hardware -- you will get much different results with different video cards and processor speed. That alone will invalidate any such speed difference tests.

Using Microsoft compilers, I am not at all convinced that std::cout is faster than printf(). I have made similar tests in the past on other computers with M$ os and have never seen one where cout is faster than printf(). And I would be supprised if *nix computers was any different.

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

I find no problem in doing it. Have you done the modifications I told JoBe in a previous reply ( Reply Number 10 in this thread )? Can you make GUI Applications in Visual Studio 2005?

I don't have a problem described in reply #10, but the one in previous reply #9. And yes, I did follow the steps in that M$ link about how to set up the compiler for windows applications -- that's not my problem. But thanks anyway.

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

I have had the same question about how to disable UNICODE settings -- thanks WolfPack for the help. But even after that, I also get the unresolved external MessageBox error. Can't it be used in console applications?? I use it in console apps with VC++ 6.0 compiler without any problems. Maybe we just can't use in console apps with that free Express edition compiler. Otherwise, the other win32 api functions I use (FindFirstFile(), FindNextFile() etc) compile and link ok.

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

>>Why do folks assume that old is bad?

My wife is getting old too, but she's still in good working order and I intend to keep her around for awhile. Already have her broke in, getting a new wife means I have to start all over again. :)

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

fflush(stdin);

Basically wut does fflush do? I dont quite understand it. I read a few books about it but still doesnt quite understand how and the purpose of fflush(stdin).

There is NEVER an appropriate use fflush(stdin) -- fflush is used to force the operating system to write buffered information to the hard drive (or other mass storage device), stdin is a file handle used for keyboard input or sometimes redirected data file input, so fflush(stdin) has undefined behavior.

If you don't know what a function does then avoid using it until you read and understand its behaviors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
fflush(stdin);

That is non-standard and may cause unpredictable results. fflush() is only guarenteed to work on output devices. Why are you using it in your program anyway -- the program isn't getting any input from stdin. Just delete that line.

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

just write a short trim() function that searches the buffer backwards from end to beginning and put a 0 byte just after the first non-white-space character. In C do it like this: c++ would be similar. make sure you do not pass a string literal to this function because string literals are normally in read-only memory.

#include <ctype.h>

void trim(char* buf)
{
    char* s = buf + strlen(buf)-1;
    while( s >= buf)
    {
        if( !isspace(*s))
        {
           *(s+1) = 0;
           break;
        }
        s--;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

one place a reference is needed and pointers will not work is overloading the [] operator. You couldn't implement this as neatly using pointers.

And the reference can be used on both left and right side of the operators, as illustrated in main() below.

#include <iostream>
using namespace std;

class matrix
{
private:
	int array[10];
public:
	matrix() {memset(array,0,sizeof(array));}
	int& operator[](int index) {return array[index];} 

};

int main()
{

	matrix m;
	m[0] = 1;
	m[1] = 2;
             int x = m[2];
	cout << m[0] << endl;
	cout << m[1] << endl;

	return 0;
}