collapse collapse

* Who's Online

  • Dot Guests: 110
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Nathan

Pages: 1 ... 41 42 43 44 45 [46]
C++ / Re: when to use ' instead of "
« on: December 07, 2008, 04:36:26 pm »
You use ' when your comparing a single character, you use " what comparing a word or sentence.
Or use " when comparing a string with another string.

C++ / Re: playing music/sounds
« on: December 07, 2008, 10:16:25 am »
right now i'm trying to play sounds although it isn't working too well. heres what i've got (with a little help)

Code: [Select]
#include <windows.h>
#include <mmsystem.h>
int main()

return 0;
Next time can you post please what errors you get/what it is/isn't doing?

But I Think this might help:
My guess is that you aren't linking with the right libraries.

Suggestions / Re: areas for program checking
« on: December 06, 2008, 10:54:34 pm »
maybe you could add a place on the site where you enter what you have and the site checks to see if everything is correct.
I mean I could imagine someone putting that together, but in reality it would only invoke a compiler and output the results. Which begs the that point, why couldn't you just call the compiler on your computer to check the code? ;).

I mean, I suppose it would be possible to analyze code and report back what was wrong/how to fix it....but something like that would be EXTREMELY difficult.

C++ / Re: identifying a specific word in a sentence
« on: December 06, 2008, 10:33:19 pm »
What happens if there are multiple instances of the same word? The find is worthless then. It only goes to the first one.
Actually according the article -
find returns the position of where the "needle" was found. find also allows you to specify a starting position.
Code: [Select]
  if (found!=string::npos)
    cout << "first 'needle' found at: " << int(found) << endl;

  found=str.find("needles are small",found+1,6);
  if (found!=string::npos)
    cout << "second 'needle' found at: " << int(found) << endl;

C++ / Re: [12] Arrays
« on: December 06, 2008, 09:59:19 pm »
Some compilers don't implement array out of bounds checking.
For example:

Code: [Select]
int num[4];I compile it and run it, but then I change it to
Code: [Select]
int num[3];And I try to do something at num[3], the program may not give me an error because it might be accessing a part of memory that is available. Or it might be careful and remember arrays start at 0 :).
(This "behavior" actually happened to me, and I was sitting there trying to figure out why I couldn't set an array element!)

C++ / Re: identifying a specific word in a sentence
« on: December 06, 2008, 09:38:37 pm »
You would have to break the sentence apart. Use a string to store the entire sentence. From there, use a loop to circulate through characters and store those characters into a variable until you hit a ' ' (space), then pass the word into another function that compares if that word is what you are looking for. If its not, then continue looping.
Way more complicated than it needs to be.  ;)
The string class provides a function to do just this:

C++ / Re: making random sentences
« on: December 06, 2008, 09:36:48 pm »
is there a way i can assign a sentence to a number so that when a random number is made, the sentence assigned to it will be said
Well one way would be to make an array of strings like this:
Code: [Select]
//assume an int called nRand that has a random number
string words[10];
words[0] = "someword";
words[1] = "word2";
cout << words[nRand] << endl;

C++ / Re: [3] Onto While Loops!
« on: December 06, 2008, 05:45:52 pm »
how would you make it run until it's at a specific number or over?
I think this will work for you:
Code: [Select]
while(num <= max)
//while num is less than or equal to max run this code

Beta Releases / Re: extremely easy script
« on: December 06, 2008, 01:39:00 pm »
well actually in order to use system commands you have to include <windows.h> otherwise it will not compile. also getchar(); is used just to wait for the user to end the program. its the way i learned from celestial so thats the way i do it. yea cin would work but i say patato and u say potato. and no i guess it doesn't matter if you put void into the argument but it just pointless so y waste the time. and no its not wrong but we're learning C++ not C.
My apologizes, but system is not defined in cstdlib (the C++ library for many C functions which include system) but in cstdlib.h (which cstdlib includes stdlib.h):
Line 358: _CRTIMP int __cdecl   system   (const char*);
(I included it for your viewing pleasure!)

I examined windows.h and related includes and couldn't find a definition for system. system function is a crossplatform function that would not be located in windows.h anyways.

I think you are thinking of the ShellExecute Windows API.

Ahh ok, I thought you were telling him to use getchar instead of cin...I was like "what?". And yes you do have a valid point there :).

And as far as the main(void) vs main() since both are correct, its really a matter of a programmers preference. Every programmer has their own "style" and if its not wrong, then why argue about it? :).

System function is crossplatform. See my example C++ file and after compiling with g++ on Ubuntu 8.04 (Linux) (g++ test.cpp -o test) it spit out a binary which worked (also attached). Please do note that you do not need to include cstdlib with the GNU compiler as it automatically includes certain libraries (such as, but not limited too, cstdlib, and string). Bad practice, yes, but it is lunch time and don't feel like fixing it :).

Beta Releases / Re: extremely easy script
« on: December 06, 2008, 12:35:45 pm »
first off there are just 1 or 2 things wrong with your program.
the first thing and probably the most wrong is using system("pause"); command.
well its bad to use it because it is hell on the CPU and it goes straight to the system just to pause a simple program so avoid system commands. second in order to use system commands u have in include <windows.h> or you'll get an error.
the better thing to use is getchar(); and if one doesn't work then try 2 back to back. its much safer and better.
also if you are using a main function of type in you don't have to put void in the parenthesis. its just not a good idea so don't do it. that is where you would put an argument and u rarely use arguments for a function like main.
other than that good job.
Lemme just add my 2 cents.

System does not require any processor time really, all system does is invokes a command and when that application returns an exit status it resumes execution of the program (observable using system("pause"); ). System is defined in windows.h, but for the crossplatform libraries it is defined in cstdlib (and the older stdlib.h) (see

In this case cin is the best thing to use because cin is overloaded to handle double. Getchar is not. Getchar will return the value of the character that was inputed. In this case you do not want the value of the char but the value of the number. You can convert a char to a number pretty easily, but its stupid to do it in C++ when you have all the tools available to you. One is not really "safer" over the other. I'm not 100% sure about this, but cin might "throw" an error if you input a character rather than a number.

Putting void in the parameters for main is a remanence of C. Is it wrong to do it? Not at all. Putting in void is like putting nothing. The major thing is that main returns an int, other than that...the parameters are optional.

Introductions / adamsna
« on: December 05, 2008, 10:26:50 pm »
Well, I suppose I should properly introduce myself instead of lurking in the shadows...

My name is Nathan Adams, and I am a computer science major who deeply enjoys working with his computers.
I started a hosting company called Datanethost about a year ago, and although I don't make a lot of money, that is not why I started it. I started it for communities like this one that either can't afford hosting or don't know how to go about it. I manage the technical side of things, and let them worry about the "actual" community :). All ad free of course.
I run Linux and Windows Server 2003 servers, though I find Linux to be a lot easier to maintain/use for server related things :).

I code mainly in C++, PHP, MySQL, HTML and some Javascript/AJAX on the side. I do know VB6, BASIC, VB.Net to an extent and now just recently Assembly.

Codeblocks is my weapon of choice, though I find I turn to Microsoft Visual Studio on occasion. I have an open door policy (most) of the time. So, if you ever need anything or have a question feel free to ask me directly.

I am currently dead locked in writing a book on Linux, so if you want to see a book by me...please feel free to send me donations :).

I have also started several projects:

If you would like to help out with any of them, let me know...I'm sure you could help out with something :).

General Talk / Re: Your Own Program or Game
« on: December 05, 2008, 10:14:50 pm »
Lets not forget my game engine IrrLib :).
Its an engine written in C++ using Irrlicht for graphics and Newton for physics. Right now it can easily be used for 2D games, 3D stuff is still in the works.

See for a little preview.

Beta Releases / Re: Simple Keylogger
« on: December 05, 2008, 10:10:10 pm »
um...simple? that thing is huge! i've been learning lua for a year and i can just barely make something as long as that
Lua is a different language. For example in Assembly that same code would probably be easily 10x the size of that. And by the looks of Lua I would guess it would take appx the same amount of code.

C++ / Re: [2] Talking With The Keyboard
« on: December 05, 2008, 02:53:39 pm »
2 questions
1) Can i use \n instead of endl?
2)Whats the difference between the two
i ran the program and it ended soon as i pressed enter so i added a cin.ignore()
Many programmers use system("pause"); to "pause" the program.

The different between \n and endl is that...there isn't one! endl is either a const for the newline character or macro defined. Which one should you use? That question is kinda hard to answer, but in reality if you used \n it would be faster than using endl because the compiler doesn't have to replace endl with \n. At least that is AFAIK.

Updates / Re: Chatzors
« on: December 03, 2008, 08:56:29 pm »
I was trying to find a PM system.
Doesn't SMF have PM builtin or am I missing something? o_O

C++ / Re: [13] Structures
« on: November 30, 2008, 10:48:46 pm »
In line 4 of your second example you seem to have a period that snuck in there

Code: [Select]
. <---
typedef struct _CASH {

Pages: 1 ... 41 42 43 44 45 [46]


* Search

* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]

Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]

Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]

Updates by Nathan
[October 30, 2015, 08:27:36 pm]