DeanMSands3 69 Junior Poster

Check out Stratagus and SpringRTS (both easily Googled)
Get a content-creation team together and see what you can add to it. Once you've gotten "modding" down, then go for the big stuff. Programming is a bear, but the real slow down is content creation.

DeanMSands3 69 Junior Poster

This will get you started.

#include <iostream>
using namespace std;
string studentName[10];
float studentMark[10];
char studentGrade[10];

char getGradeByMark(float mark){
    int iMark=(int)(mark/10);
    switch(iMark){
        case 10:
        case 9:
            return 'A';
        case 8:
            return 'B';
        case 7:
            return 'C';
        case 6:
            return 'D';
        default:
            return 'F';
    }
}

void getStudentData(int student){
    cout<<"Input name for student #"<<(student+1)<<": ";
    getline (cin,studentName[student]);
    cout<<"Input grade for student #"<<(student+1)<<": ";
    studentGrade[student]=getGradeByMark(studentMark[student]);
}




int main(){
    bool done=false;
    int option;
    for(int i=0;i<10;i++){
        getStudentData(i);
    }
    while(!done){
        cout<<"<List options>"<<endl;
        cout<<"Please select one of the options:";
        cin>>option;
        switch(option){
            case 1:
                cout<<"First option selected. There should probably be a function here."<<endl;
                break;
            case 2:
                cout<<"Second option selected. There really should be a function here."<<endl;
                break;
            case 3:
                cout<<"Third option selected. I suppose I'm lazy."<<endl;
                break;
            case 4:
                cout<<"Fourth option selected. This is not the option you are looking for."<<endl;
                break;
            default:
                cout<<"Exiting..."<<endl;
                done=true;
                break;

        }

    }
    return 0;
}
elsiekins commented: Dont give them the answer they have done nothing ! -1
DeanMSands3 69 Junior Poster

The recursive function is a useful tool.

(Wait, did he just...? Yes, I did.)

DeanMSands3 69 Junior Poster

He wakes up every morning and asks himself "What would Mr. Rogers do?" He contemplates and ponders this question until he's filled with the happiest, most peaceful and tranquil thoughts. Then he lays waste to everything that gets in his way. Happily.

Why are there PhDs without homes or jobs?

DeanMSands3 69 Junior Poster

Well, you broke the first one by using the CODE tag.

DeanMSands3 69 Junior Poster

Nice, Moschops.
For amusement, I am rewriting infamous1987's post as a proper OOP program.
I'll let you know when I'm done.

DeanMSands3 69 Junior Poster

http://www.daniweb.com/software-development/cpp/threads/341509
Props to AD for this one. I upvoted his post. You should do the same.

DeanMSands3 69 Junior Poster

Are you familiar with stacks?
A stack is a data structure that is accessed only by it's last element.
The simplest stack is made with an array and a "top" index.
When you start, you can set the top index to zero.
To add data to the stack, you "push" it on.
To push, you simply do this:

function push(data)
    if top>stack.size
        stack[top]=data
        top=top+1
    end if
end function

To get data from a stack, you pop it.

function pop()
    if top>0
        top=top-1
        return stack[top]
    end if
end function

So what you do is push ten values, then pop them back. Try it.

DeanMSands3 69 Junior Poster

I find that a lot of CS majors don't. As for myself, I do.
I had a Romanian professor. Is Romania a good place to study if you're majoring in Computer Science?

DeanMSands3 69 Junior Poster

Maybe you mean ellipse?
http://msdn.microsoft.com/en-us/library/6hkxb3kd(v=vs.80).aspx

DeanMSands3 69 Junior Poster

To keep the rest of the universe safe. Who knows what would happen if we actually knew what we were doing.

If a lawyer and a mime were crossing the street and speeding truck came towards them, which would you save if you could only save one?

DeanMSands3 69 Junior Poster

To what platform or format?
If you're talking about to the console, eh, you're going to have to write a function that generates an array of multiple lines and offsets the sub and super script text to their corresponding position in the main line of text.

For example:

n   2
a=E   i
   i=0

The n and the 2 in the superscript have to be spaced to match up with the E and the i respectively. The i=0 has to be spaced to match up with the E.

And that looks like it'd be fun to write.

DeanMSands3 69 Junior Poster

You only have pointers. The memory space isn't allocated yet. If you were using arrays, that'd be different.

struct Adress{
        char street[32];
        char postal[32];
        int zip;
    };

    struct Person{
        char firstName[32];
        char lastName[32];
        struct Adress home;
    };

EDIT:
This might be helpful.
Stanford Explains Pointers.

DeanMSands3 69 Junior Poster

(Ah, see. Now we've reversed. Give a stupid answer, get a stupid question!)
Question to previous statement: Then why do you keep posting?


Answer to next question: 42.

DeanMSands3 69 Junior Poster

Life is a precious gift to all - to men and to ants.

Aardvark

DeanMSands3 69 Junior Poster

Wellness and serenity are our common goals.

DeanMSands3 69 Junior Poster

You can't use arrays? Can you use linked lists or trees?
EDIT: How did we all reply at the same time?

DeanMSands3 69 Junior Poster

If you go with Eclipse or NetBeans (and I recommend it), you'll need an external compiler.

MinGW is a GNU C Compiler suite for Windows. And it's pretty sweet.
You can either get the original or TDM-GCC (which is an unintentional pun on "tedium").

MSys is a minimal system which provides a Unix-like environment to compile the code in.
If you want a Make system (you do, but you probably don't know it yet), you want MSys.
If you have external libraries or programs that ask for the "./configure && make && make install" method, you want MSys.
Seriously. You. Want. MSys.

CMake is a program that replaces configure to generate the make files. This is often pretty helpful. You will eventually want this.

All of which are easily googled.

DeanMSands3 69 Junior Poster

What version of Allegro are you using? That looks like older Allegro code.
Allegro 5 uses a whole new API.
I compiled Allegro 5 on my system using MSYS, MinGW and CMake.
Then I tried compiling that code. Didn't take.
Tried code from the Wiki.
Worked without any problem.

DeanMSands3 69 Junior Poster

I haven't gotten any done or even close to started past a very loose framework, but when I finally do this is how I'll do it:
C++ (I. NEED. MORE. SPEED.)
SFML (On Windows, Mac, and Linux)
Home brewed. (Because the little men who live in my toes tell me to.)
RPG (Because the little men who live in my toes are the only friends I'll ever need.)

DeanMSands3 69 Junior Poster

Are you giving QUWI enough time to finish?
It looks like you're queuing the thread, then exiting.

Have a look at this:
http://developer.amd.com/documentation/articles/pages/125200687.aspx
In this code, when the last thread finishes, it signals an event, which the main function waits for before exiting.

DeanMSands3 69 Junior Poster

Fantastic. I'm glad to have helped.

DeanMSands3 69 Junior Poster

A char tends to be 8 bits.
An int on a 32-bit machine is 32-bits.
If an int contains a 2, it actually contains {2,0,0,0} (in a 32-bit system)
Try this code:

#include<stdio.h>

int main()
{
	unsigned int i, j;
	int arr[3]={2,3,4};
	char *p;
//	p = (char*)arr;         // line A
	for(i=0;i<3;i++){
		printf("Integer:%d\n",arr[i]);

		for(j=0;j<sizeof(int);j++){	//I'm using sizeof(int) to get the exact size of int. I can't assume it's 4.
			p=(char*)&arr[i];	//point p at arr
			p+=j;			//move p to current byte
			printf("Byte[%d]:%d\n",j,*p);
		}
		printf("*********\n");
	}
	return 0;
}

Why do I not know the size of int?
An int is usually the size of the number of bits in the system it's compiled for.
This can be 16, 32, or 64.
Note that just because I run a program on a 64-bit system, doesn't mean I'm getting 64-bits. If it's a 32-bit program, it's a 32-bit number.

student_learner commented: gives the accurate answer. :) +1
DeanMSands3 69 Junior Poster

No. But I will give you this.

#include <stdio.h>

int main() {
	int i;
	char oneDimensional[]="I am one-dimensional!\n";
	char twoDimensional[5][5]={
			"I am",
			{'t','w','o','-',0},
			"dime",
			"nsio",
			"nal!"
	};
	printf("%s",oneDimensional);
	for(i=0;i<5;i++){
		printf("%s",twoDimensional[i]);
	}
	return 0;
}

Which outputs this:

I am one-dimensional!
I amtwo dimensional!

Yes, I know it's missing a space. However, to keep it inside 5x5 and include the trailing 0's at the same time, I realized I was too lazy to fix it.

DeanMSands3 69 Junior Poster

Allow me to make some adjustments.

#include <iostream>
#include <string>
#include <vector>
#include <cstring> 
#include <cstdlib>

using namespace std;

class ship 
{
	char Name[256];
	vector<string> inventory;


public:
	void setName(char *nam)
	{
		strcpy(Name, nam);
	cout << Name;
	}
	
	void addToInventory(string frt, string sec, string thir)
	{
		inventory.push_back (frt);
		inventory.push_back (sec);
		inventory.push_back (thir);
		cout << inventory[0]; //Is this really needed?
	}
	void listInventory()
	{
		for(int i=0;i<inventory.size();i++)
		{
			cout << inventory[i]; 
		}
	}
};

int main()
{
	
	char shipcall[256];
	ship player;
	cout << "welcome to space \n";
	string frt = "Credits";
	string sec = "cargo";
	string thir = "Armaments";
	
	cout << " Name your ship\n";

	cin.get(shipcall,156);
	
	player.setName(shipcall);

	player.addToInventory(frt, sec,thir);
	
	player.listInventory();

	system ("pause");
	return 0;

}
DeanMSands3 69 Junior Poster

I had to google that to figure it out. And hey, me too! Do you have a date set?

DeanMSands3 69 Junior Poster
long fileSize;
fseek(input, 0L, SEEK_END); //Go to end of file
fileSize = ftell(input); //Current position is the file length
rewind(input); //Rewind to beginning

Then just do a for loop.

As for speed, your fgetc is killing you. Single character reads is too slow.
Once you know your file size, malloc a buffer, and fread into it.
Then fwrite out.

DeanMSands3 69 Junior Poster

It's a bright beautiful world out there. Let's fix that.

DeanMSands3 69 Junior Poster

We have 32 data gathering sources all operating at 100Mb. They tie to a single server.
Currently, we're using a 100 Mb network.

We've have 2 Trendnet TEG-424WS units we can put in. They come with 24x100Mb ports and 4x1Gb uplinks.
Can we tie the server to one of the GB up-link spots and have it get the benefit of the full 1Gb (or a reasonable approximation) or will we be stuck with the server only getting 100Mb with each data source taking a turn to talk to it, one at a time.

"Try it and see" is not an option.

DeanMSands3 69 Junior Poster

Playing with fire will get you burned.

DeanMSands3 69 Junior Poster

To make computer programmers feel better by comparison.

If a three-legged stool has one leg measuring 14.5 inches, one leg measuring 14 inches and one leg measuring 13.5 inches, assuming a steady level surface, how often will the stool wobble?

DeanMSands3 69 Junior Poster

((24^2)-1)/(24-1)

DeanMSands3 69 Junior Poster

Floats and Doubles see the world much differently than integers do. Do an is it equal to...? will probably have some weird results.
My advice, change it to while(!(hoursWorked<0))

Reference:
http://en.wikipedia.org/wiki/IEEE_754-2008

DeanMSands3 69 Junior Poster

Have you set up port forwarding on your router?
Secondly, have you tried accessing your server from a computer outside your local network - like a laptop at an internet cafe.

Reference:
http://en.wikipedia.org/wiki/Port_forwarding
http://portforward.com

DeanMSands3 69 Junior Poster

Scripting engines and graphics loading, saving & manipulations.
See if you can take a script, some single frame sprites, background tiles, and generate a single scene. Export it to JPEG or PNG.
Heh, I need to try that.

DeanMSands3 69 Junior Poster

I should mention that both SFML and SDL are built on or work in tandem with OpenGL.
Which will work on Macs as well as Windows PCs. As well as Linux PCs.

DeanMSands3 69 Junior Poster

This is what a GET looks like. (I'll admit I still haven't gotten the hang of which formatting blocks to use for these.)

GET /7357.php?Test=This+is+a+test. HTTP/1.1
Host: prc-web
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP/1.1 200 OK
Date: Sat, 11 Feb 2012 01:11:57 GMT
Server: Apache/2.2.17
Content-Length: 153
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

<html>
	<head>
		<title>
			This is a test.
		</title>
	</head>
	<body>
		<pre>Array
(
    [Test] => This is a test.
)
</pre>
	</body>
</html>

Now for a POST.

POST /7357/index.php HTTP/1.1
Host: prc-web
Connection: keep-alive
Content-Length: 658
Cache-Control: max-age=0
Origin: http://prc-web
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryW9MPp7q6VrfE1jOx
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://prc-web/7357/postTest.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="String1"

Hello!
------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="string2"

This is a test!
------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="type"

true
------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="string3"

I like hats!
------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="HatsAreAwesome"

true
------WebKitFormBoundaryW9MPp7q6VrfE1jOx
Content-Disposition: form-data; name="submit"

Submit
------WebKitFormBoundaryW9MPp7q6VrfE1jOx--

And the response:

HTTP/1.1 200 OK
Date: Sat, 11 Feb 2012 01:59:15 GMT
Server: Apache/2.2.17
X-Powered-By: PHP/5.3.5
Content-Length: 281
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

<html>
	<head>
		<title>
			This is a test.
		</title>
	</head>
	<body>
		<pre>Array
(
    [String1] => Hello!
    [string2] => This is a test!
    [type] => true
    [string3] => I like hats!
    [HatsAreAwesome] => true
    [submit] => Submit
)
</pre>
	</body>
</html>

The Array you see is just the $_REQUEST …

DeanMSands3 69 Junior Poster

...at what point do you start to learn the more advanced stuff?

When your professor's first spoken language is not the same as your own. That's when you get into the crazy stuff.

DeanMSands3 69 Junior Poster

Currently working on the explanation.
(And you do know you're basically writing a fake web server, right? Awesome.)
(And if you don't have a copy of WireShark, get one. Point it TCP Port 80 and watch the magic happen.)

DeanMSands3 69 Junior Poster

@ravenous: Yeah, I noticed that too, but got caught up in dusting off the math brain cells that I forgot to say anything about the "acceleration" and "initial acceleration" bits.
And I modified my copy to use doubles. I also neglected to mention that.
And nice use of Latex. I completely forgot this board has that.

DeanMSands3 69 Junior Poster

These two links should help.
http://www.daniweb.com/software-development/cpp/threads/117408
http://stackoverflow.com/a/236803

First you delimit by ? which breaks the address and the parameter list.
Then you delimit the parameter list by & which breaks it into individual key/value pairs.
Delimit by = to separate the keys from the values. I'd recommend using an STL map, mapping the keys to the values.

DeanMSands3 69 Junior Poster

Something's wrong somewhere and I'm not entirely sure where. It seems like it SHOULD WORK, but SHOULD WORK rarely works the way it should.

Have a look at this:
http://en.wikipedia.org/wiki/Equations_of_motion#Applications
(I don't know why they picked the variables they did, but they did.)
A free fall object at point s reaches a final velocity of u after t seconds.
To find u, take the square root of s divided by 2 times the Gravity constant (acceleration).
The code looks like u=sqrt(s/(2*G));
Divide u by your G to get your time.

DeanMSands3 69 Junior Poster

A moving average would look like this:
Average = 0.0 (Use doubles)
Number of elements = 0.0
Total = 0.0
While there are more numbers:
Ask for a new number.
Add new number to total.
Add 1 to number of elements.
Divide total by number of elements.
Store in average.
Loop

And here is a lovely snippet of code for you to get you started.

#include <stdio.h>
int main(){
    double average=0;
    double sum=0;
    double entry;
    char keepGoing='y';
    while(keepGoing=='y'){
        printf("Please input your value: ");
        http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/

        // Do something awesome.

        printf("Keep going?");
        //http://www.cplusplus.com/reference/clibrary/cstdio/fscanf/
    }
    return 0;
}
DeanMSands3 69 Junior Poster

Read this code, then fix it.

#include <string>
#include <iostream>
using namespace std;
int main(){
    string s1="123"; //Set up string 1
    string s2="456"; //Set up string 2
    string s3;       //Setup string 3

    cout<<"First  string: "<<s1<<endl;
    cout<<"Second string: "<<s2<<endl;
    s3=s1;           //Copy string 1 into string 3
    for(int i=0;i<s2.size();i++){        //Loop through s2
        char c=s2[i]; //Grab current character from s2
        bool is_c_in_s3=true;
        for(int j=0;j<s3.size();j++){    //Loop though s3
            cout<<"Figure this portion out yourself."<<endl;
        }
        if(is_c_in_s3){
            s3+=c; //Add the element to String 3
        }
    }
    cout<<"Final string: "<<s3<<endl;
}
DeanMSands3 69 Junior Poster

Absolutely.
Write a socket server. Then write a chat server and client. When you get finished with that you will wonder why I told you to. Then it will suddenly become obvious.

http://www.codeproject.com/Articles/13071/Programming-Windows-TCP-Sockets-in-C-for-the-Begin
http://www.codeproject.com/Articles/14032/Chat-Client-Server

DeanMSands3 69 Junior Poster

http://www.cs.stanford.edu/cslibrary/PointerFunCppBig.avi

Main Page Link:
http://cslibrary.stanford.edu/104/

(If this helpful to anyone, it is technically not trolling.)

DeanMSands3 69 Junior Poster
DeanMSands3 69 Junior Poster

http://en.wikipedia.org/wiki/Hashing_function

A good hash function to get started learning is the Java string hashing function.
http://www.ibm.com/developerworks/java/library/j-jtp05273/index.html
Effectively, it's
Start with 1.
While there are more items
Multiply current hash by 31.
Add the next item.
Loop

Multiplies by 31 can be shortened into shift left by 5, subtract original.

After that try CRC
http://en.wikipedia.org/wiki/Computation_of_CRC

Then get into the good stuff.
http://en.wikipedia.org/wiki/HMAC
http://en.wikipedia.org/wiki/MD5
http://en.wikipedia.org/wiki/SHA-1
http://en.wikipedia.org/wiki/SHA-2

This is not an exhaustive list.

Also, you need to get into multiple thread/process programs.
This leads to fun things, in order of fun:
1. Creating Processes (briefly)
2. Threads (and getting values back from threads)
3. Mutexes
4. Semaphores
5. Thread-safe functions
6. Rewriting algorithms as multi-threaded
7. Processes and shared memory
8. Pipes
9. Race Conditions

Happy^H^H^H^H^H Sane Coding.

DeanMSands3 69 Junior Poster

This is a poorly made list, but I was (am) in a hurry.
0.a. Arrays
0.b. Pointers as arrays
0.c. Pointers to Pointers
0.d. Pointers to Pointers as Arrays of Arrays
(I learned Pointers by using Iceman's C rewrites of Denthor's VGA trainers.)
1. Stacks as arrays
2. Double-Ended Queues (Deques) as arrays
3.a. Single-Linked Lists in Java
3.b. Single-Linked Lists in C++
3.c. Single-Linked Lists in C
4.a. Double-Linked Lists in Java
4.b. Double-Linked Lists in C++
4.c. Double-Linked Lists in C
4.d. Double-Linked Lists as Stacks
4.e. Double-Linked Lists as Deques
6. Searching in Linked Lists
5.a. Trees
5.b. Walking Trees
6.a. Graphs / Networks
6.b. Walking Graphs (Breadth first, Depth first, A*)
7. Binary Search Trees
8. Hashing functions
9. Hash Tables

DeanMSands3 69 Junior Poster

Token plug for ported GNU compilers.
Get the MinGW/MSYS if you're using Windows, but want to run on the command line.
http://sourceforge.net/projects/mingw/files/
Grab the link near the upper middle that says "Looking for the latest version?"

Get DJGPP if you are actually using honest to goodness DOS 5.0 - 6.22 or FreeDOS, and NOT a command line inside Windows.
http://www.delorie.com/djgpp/zip-picker.html

For those in the know, DJ Delorie is a freaking awesome guy and is currently doing work on Renesas microcontrollers. You can find him in the RenesasRulz forums.