I found a very good video explaining how computers use the basic transistor component to do multiplication. I'm currently working on a project for college that requires something along these lines. Figured I'd share it since it was such a good video.

Next up is how to use php to execute a batch file on my system. I wrote a small batch that essentially executes another program for FastDL sync (as gmod caps DL at 20kb/s) but this program can take a while to complete compressing and copying files. Does something like system("C:\program.bat") work? This particular program requires me to press enter when it is finished, is there a way I could get a program to do this for me? And would the program have to hold up the entire PHP while it takes its 10+ minutes to complete? Any ways around this if it is the case? I feel like all the things I'm trying to do have horrible security concerns.

Would I be better off writing something to run on the system rather than attempting to do all this through php? I want these functions to be accessible to the web, so that I can use them.

Due to the inherent nature of php and what it is designed to do, your best option would be to write an extension for it if you want it to communicate with an outside application. I'm not very familiar with the process, but the link below is a good starting spot. What your are trying to do goes against the SOP for php, if you half-ass it and work through lots of different "work arounds" you will end up creating a convoluted system that would inherently be far more vulnerable to outside hacks, abuse or internal errors than you would doing it via an extension.

While this works and accomplishes what you want, it is not very readable. Having to dereference a pointer in order to get it's contents is something you should avoid while being a novice IMHO. It causes uneeded congestion and there are simpler ways to accomplish the same thing. One way that is a little more clear is to just reference it directly without an iterator.

Vectors are essentially arrays in memory of whatever type you specified. As such, they can be referenced as if they were arrays, making the below code possible.

Code: C++

for(unsigned i=0; i<data.size(); i++)

cout<< data[i]<<"\n";

Iterators are good when you have complex classes being pushed onto a stack or into the vector array, but for simple things like this, it is often easier to stick with the simple ways.

Moving along to this function...

Code: C++

string getinput()

{

string dataline;

string name;

cout<<"Enter Name: ";

getline(cin, name);

dataline ="Name: "+ name +", ";

string number;

cout<<"Enter Number: ";

getline(cin, number);

dataline = dataline +"Number: "+ number +", ";

string address;

cout<<"Enter Address: ";

getline(cin, address);

dataline = dataline +"Address: "+ address +" ";

return dataline;

}

Since you are using different variables to store the information, you don't need the many appends. You could instead clean it up into one line similar to below.

As far as the global namespace goes, as long as it is only used inside the source file, I don't really see an issue with it. I never understood the arguments against it. You only run into issues when placing them in headers or when you find the 2 most unlikely conflicts in defines or naming conventions with non-standard libraries. It is such a rarity that I don't agree they are bad. I do, however, think they should be left outside of headers since you may not always want a scope to be active in all things including it.

As far as a support section goes, I actually thought I had one up. Maybe I haven't shown it to all users yet. I'll check it out.

// First, create a handle to a new file to write the compressed contents to

compressedFile.open("newFile.txt", std::ios::out| std::ios::binary);

if(!compressedFile.is_open()){

std::cout<<"Unable to create file.\n";

return-2;

}

// Iterate through stored data and look for repititions

// Start looping through the data to get the first data to check for

unsigned uBuffSize = sContents.size()-1;

unsignedchar ucCurrentByte;

unsignedchar ucCompareByte;

unsigned uCurrentPosition =0;

while(uCurrentPosition < uBuffSize){

// Select the byte to look for repeats

ucCompareByte = sContents.at(uCurrentPosition);

// Keep track of how many times the character repeats.

// Never go above 9 repeats

unsigned uRepeats =0;

// Find all repeats

while(true){

// Increment the position by 1

uCurrentPosition++;

// Make sure we don't go over the buffersize

if(uCurrentPosition > uBuffSize)

break;

// Grab the next byte

ucCurrentByte = sContents.at(uCurrentPosition);

// Check if it repeated

if(ucCurrentByte == ucCompareByte){

uRepeats++;

if(uRepeats >=9)

break;

}else{

// If it does not, then we need to break out of this

// check, write what we found, then continue on to the

// next character

break;

}

}

// Prepare the data for writting

std::ostringstream strOut;

if(uRepeats)

// If there were more than 2 repeats write the number of instances

// and the byte that was repeated

if(uRepeats >2) strOut << uRepeats << ucCompareByte;

// Otherwise, just write out the 1-2 repeats

elsefor(int a =0; a < uRepeats; a++) strOut << ucCompareByte;

else

// If there were no repeats, just print the character that was affected

strOut << ucCompareByte;

// Write the reults to file for this comparison

compressedFile << strOut.str();

}

// Close the file we were writting to.

compressedFile.close();

std::cout<<"Compressed!\n";

return0;

}

Reading and decompressing the file is not show in this, but it is a simple matter of looking for identifiers (numbers 3-9 in this case) and then just repeating that data in memory to decompress the file.

It is going on 7 years this year that CelestialCoding has been hosted by Nathan. Over those 7 years, we have compiled and created many tutorials for anybody who happened to stumble onto this site and had a desire to learn. During the 7 years though, issues have begun to crop up and I thought it was time to nip them before it became cancerous.

Before I get into why this is happening, please understand this does not in any way affect the nature of this website. This site always has and, as long as it is within my power, always will be a free opensource tutorial site dedicated to helping the everyday guest learn programming or similar practices.

I mentioned before that some issues were starting to crop up. Most of these issues revolved around tutorials being either deprecated, inaccurate, superfluous, useless, incomplete, or otherwise aimless. The website's shoes were also starting to become a little too big to be filled by itself. Many categories were empty, or have only a single tutorial in it while others were the main area of interest. This redesigned is aimed to fix those issues.

I do hope that active users will respond to this post and lend me their input or ideas on how to categorize the website. I would love to hear some ideas but for now, here is the idea.

1. Focus the site around Tutorials with 1 tutorial area that has what can be called "high quality" or "complete tutorials".2. No more categories for different languages, they can all be grouped together since only 2 languages were actually common in the 7 years of the websites activity. All languages and tutorials are still accepted, but there will be no more segregation of the languages. 3. A trial area for common tutorials that are good, but involve incomplete series, or is somehow inaccurate or causes some sort of issues will be created as well. This will be a "trial" area for tutorials until they get moved to the other zone.

Those 3 points are what the site is now based around. I intend to revamp the main page as well after I am settled with the current design.

Looks similar to Tibia's ico 2d view. Do you intend to use scrolling for the landscape in similar fashion to mario or just flip the page like old school Pokemon does? It looks pretty nice, I've been distracted playing Dungeon Defenders 2. About time I get back to work on my project as well.

Just adding a small update.... Well, not so small internally, but it is small when it comes to notability for user side stuff. You can modify the resolution yourself now by modifying the userSettings.xml file in the userData folder. I've also upgrade the logger to catch WAY more errors then last time. IT is all in 1 file now too instead of a large number of files. Currently supported resolution:1920x10801600x9001280x10241024x768800x600

Any custom resolutions you try out that are not pre supported will give odd effects. To change to fullscreen, modify the Windowed option to 0. Have fun!

EDIT: I've updated the sneak peak to include new features such as a very basic GUI/HUD/Settings system. Most of the modifications are behind the scenes,so you will not see much change from the previous demo aside from some HUD elements and some new GUI menus. A few points of interest you may want to look at...1. Look through the template/layout files inside the GUI subfolder in resources.2. Look through the settings file located in userData folder.

By customizing these files, you can pretty much create your own GUI. I've made it pretty simple to understand in my opinion. All GUI elements get resized dynamically during load time to fit the resolution. This will preserve the location, width, and height of the element while it is on screen. It also preserves the collision box for each GUI element with the same scaling.

Tell me what you think, ideas and critics are welcomed.

DOWNLOAD: Bottom of the post...

***********************************************So I've been promising Shishka I'd post something to show the progress. I've attached a sample build of the program that may or may not work... There is a lighting issue I've not yet tracked down where the bug is located at. If you run the application, see the intro, and the entire scene looks black, then just alt+f4 out of the application and attempt to run it again. It is set to run in fullscreen mode by default. There is no windowed mode quite yet.

using namespace std;I suspected this was what you were doing when I didn't see any namespace specifier explicitly within the cpp source and any using directives... The reason is because now if somebody goes to use your header, certain unintentional identifier ambiguities may exist, even if his/her code was careful to avoid them. Irregardless, writing that anywhere in your code essentially defeats the whole point of namespaces.

It was a quick and dirty demonstration of the class' use. No need for setting anything more complicated up. There is nothing wrong with using globals anyhow with small programs. It only comes into play when you use larger applications and your code starts looking like spaghetti code. In term of 'good' and 'bad', programming is still suffering from all the pitfalls it has had in the past and there is plenty of programming that goes on everyday with professions that I, and many others, consider bad practice regardless of if they use globals. I feel like this one was nitpicking.

I also think that the use of third party libraries/headers is almost cheating, especially since this wasn't specified within the guidelines in the first post as to whether or not they could be used. Otherwise, perhaps helper libraries can be used (BOOST?), and there must be in place, some form of limitations as to what kinds of libraries you can use, based on what they do.

This challenge is really as trivial as understanding how to write a table of contents (to the header metadata of the output file) and the file binary data in the structure specified within that structure header to a single file... Separators if naive, but this would be less efficient IMO.

I only use the derint header to traverse directories. This action is a LOT easier in Linux then it is in windows. Windows has no true functions to traverse directories, it only has very basic and clunky methods which would cause the code to become close to unreadable. ALL file input and output is done using the native OS, only directory traversal is using the derint header. If you were to use boost, it would take the majority the functions over since boost gives you plenty of alternatives for traversing, reading, and writing to files.

All in all, the main thing to remember here is that this is a response to a specific challenge. No need for proper etiquette when your writing code for a specific 1 goal purpose.Thanks for your input otherwise.

EDIT: So.. there is some memory issue with this. I'm not sure where, but I'm working on fixing it... Damnit EDIT2: Fixed it. I forgot to remove some padding I wrote to the file causing the offset to be 10 bytes off giving strange characters. Updated the code. I also added in some new code to grab the file from memory. Check it out. Updated attached file to reflect the new archive file.EDIT3: Modified the code slightly to fall in line with certain etiquettes.

Here is my entry for this challenge. I based the entire system off of books. Each page in the book is a set of files and each book has a table of contents with offsets pointing to each chapter (specific file on a page). For now, all you can do is create books, read their stored data, and tear them apart. I can improve this and I most likely will later on for use in some of my projects that have a large amount of files.

FEATURES!- Preserves folder structure and will recreate folder structure when tearing from the book.- Easy to use- Mostly error proof* All major points are checked for errors, but once things get rolling, the program assumes you won't have a power outage or something similar- File structure is explained indepth in the header- Very well commented

LIMITATIONS!The limits of this program are basically described by the data types it uses.It can store up to (unsigned short)[65,535] files and directoriesIt can store up to (unsigned long)[4,294,967,295] Each page it adds to the book can also be around that size as long as it does not exceed a long's size;You MUST use '\\' characters instead of forward slashes. Not doing so will cause bad things to happen... Like memory overflows.

- The class is not 100% cross platform. Each OS has different ways to create files/directories. Because of this, I focused on the Windows OS while making this.Note that I tried to keep the data structures and functions very obvious. It should be easy to port this if anyone wants to do that.

- This was built for Multibyte projects. Attempting to use this in a unicode environment will cause it to fail. If you wanted to convert it over to unicode, you would have to change all the strings to wstrings and exchange a few functions that make heavy use of those strings.

See if you can do better, or improve on my design if you don't know where to start.

[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

OH YEA! If you need a example, I've included the entire project as a archived source in my own format.

Challenge: Create a simple class that works similarly to WinZip or Rar. No compression is needed for this challenge. The goal is to implement your own version of grouping multiple files into 1 file while still preserving the data.

Any extras you add in are up to you. There requirements to full fill are below.

:REQUIREMENTS:1. Must be able to combine at least 6 files into one2. Must be able to preserve folder structures3. Must be able to extract files4. Must be able to preserve files of different types

(unsigned 32 bit) 0xC0DE = 4937400000000 00000000 11000000 11011110At the 17th index of the binary representation of the number 0xC0DE (49374), we see our first 1. Cyclically iterate the bits within the given bit mask and grab characters based on all of the set bits.

The result of the described algorithm and the number above, on the string "The apple fell from the tree." would be:

Just another update on my terrain/weather system. See the image below.

It demonstrates a few techniques currently being implemented in the scene. The techniques can be seen below. When examining the image, understand that the terrain map is HUGE. The camera is 12 units up which is equal to about 120 ft in the game world.

1. Level of detail - Notice area circled with arrow. The detail map only renders detail to a certain distance away.2. Day/Night system - The image was taken during morning hours.3. Multi texturing - Texturing system is based off height of terrain and the main texture that is laid over the entire map and then enhanced using LOD.4. Spanning clouds - Clouds contain multiple textures blended together moving at different rates. I'm debating using a perturbed image to change the cloud forms, but for now, I don't really care enough about sky detail.

Next up, tessellation for higher map detail nearby and some actual environmental objects such as trees.

"Even if it is implicit, they are still declared as either private, public or protected. Just because you don't specify one, doesn't mean it's not, by default, set to private." - This is what I said though:

Sigh. Mr. Key, can you please just delete all of our posts up to the point at which this began? I would appreciate it.

I cannot delete all of the posts since he has valid points I believe are constructive and important for a general programmers to know and understand. I can and will however remove some of the more emotional posts that contain no real value.

Understand that I will not being doing this again. Next time, I will lock the post as is and issue a warning.

1: No, I wasn't a Pascal programmer. My naming conventions are efficient for me.2: I know what Strings are. This should easily show it: "if (Word_LowerCase[0] != 'y')"3: http://msdn.microsoft.com/en-us/library/11w09h50%28v=vs.110%29.aspx4: I think System.Console.Out.WriteLine is better, as I know exactly where WriteLine is coming from.5: I don't use LINQ because I haven't learned LINQ, yet. Also, I don't program in C# often, so I didn't know about Select either.

I agree with you 100% here. I thought your post was tailored quite well to the question asked.

I thought the same thing. But as said earlier... It works. Assuming that is the real source code, they did get it to compile for them and it does work correctly when you run the exe. Maybe a modified header or something similar?

char c = 'A';bool eq = Char.ToLower(c, CultureInfo.CurrentCulture).Equals('a');Although for user input, because you're just assuming that the integer can be parsed, you will get an exception thrown if the user enters an invalid string which can't be represented as an integer, thus you *should* be using int.TryParse() instead.

You're correct however, I didn't have a need to use it since this tutorial was for switch statements and nothing else. You don't introduce random code snip-lets in tutorials when it is unrelated. Causes confusion.

In c#, all your functions are located withen a namespace, they also have to be declared as public, private, or protected. After that they are called. Your console.writeline needs to be changed if your trying to display in information to

Console.WriteLine("{0}", num); If you are trying to display. Otherwise, can we get a copy of your original C++ code so we can help you more?

No, that's not true. Depending on where they reside, they have a default access modifier. Typically this is 'private', but they do not have to be declared explicitly.

Lots of that C++ code though is junk (there's no need for all of those variables at the top with that much scope). That defeats the whole point of the functions.

I think you're misunderstanding my answer. I never said it had to be declared explicitly. Even if it is implicit, they are still declared as either private, public or protected. Just because you don't specify one, doesn't mean it's not, by default, set to private. Also, this behavior depends on your compiler. Many compilers give options to modify the default compiler settings. Case and point, MSVS 2012 allows you to set class declarations to automatically be set to public or protected if it's not specified. This is of course bad practice since it makes code unreadable by anyone outside the project. I can not for the of me image why anyone would do this, but none the less, it is possible. Also, the question was "I am trying to convert my C++ program to C#". Last time I checked C# is ALL about OOP style programming. This means heavy reliance on namespaces.

You actually don't need to call ToString() because with the + operator ToString() will be called anyways implicitly, thus ToString() is redundant. The compiler knows that it's being assigned to a string variable (the backing value of the Text property for that Label control).

Although that is true, most compilers these day would optimize it and remove the redundancy during the compilation process. There is nothing wrong with using ToString to make the code more readable IMO.

Just posting an update on this. I've gotten a lot of the feature I want up an running now. I'm currently working on getting multi layer texturing in place and LOD put in place so that I can render my quad trees in high detail nearby and low detail far away. A small picture below of my progress currently. It is only showing the terrain loaded, but it is using a quad tree and frustum culling to only render terrain you are looking at. It also has dynamic lighting enabled but it has a strange look because of my normal calculations. Once I get something related to a game up and running, I'll ensure I post some tutorials.

Also, I've decided to work on this in DirectX11 (Most features used are still available in DX9-10). I can convert the project over later to OpenGL since the languages are pretty similar in terms of what they require to render. OpenGL makes it somewhat harder though.

That's all true, but the goal isn't to make the code smaller, as that has no real application. And though I would prefer C over C#, mager wrote the original program in C#, so I decided that he would have no use for a C version, and it wouldn't help him with coding in C#.

Point taken, didn't notice it was C# looking at the original code. Looks like C to me until I hit the ToLower function.

What if instead of using a server model, it used a p2p model? The host would 'lend' their compiler to other users and the results would be compiled on their machine and sent back? I can't see a server doing this as a good idea since you would run into dependency errors. Not to mention the fact that the program would by default be compiled for that local system architecture. If it is a teaching tool, there would be a teacher hosting the source, or so I'd assume. What do you think?

Ok. I went through your code, and realized that it was very repetitive and didn't utilize C# for the one reason it's a decent language: it's massive pre-made libraries.Here is an optimized version of your code.

// Notice that words starting with silent constanants don't get processed correctly with this algorithm.

String Sentence ="happy duck glove egg inbox eight you hour";

System.Console.Out.WriteLine(ToPigLatin(Sentence));

}

}

}

There are many better ways to accomplish this. Using actual C++ classes could allow the code to be even smaller than the C# version you posted. Even C has some functions that could have made this easier.

* One that I REALLY WANT is a clone of codepad. I would like collaborative editing but compiling/running would be awesome. It's not a hard idea - but there are few caveats such as restricting internet access (don't want random people to build a malware application to attack or listen on a port - I think a short timeout period for anonymous, longer but still short for registered and longer for paid people), running it in a sandbox such that it can't access any files on the system except in the directory that was created to run it (which would also allow for registered users to upload libraries). Anyone attempting to exploit the system would be automatically banned.

Isn't this the same as the CCTC thing I built a while back. Basically multiplayer notepad, right? I remember the developement went smoothly until for some reason my ISP derped my connection and I couldn't test/debug it anymore.

This would be way different. This isn't just storing a copy of the code like a gist but rather compiling it, running it, and showing the output. These tools are great for showing examples/explaining things - especially if the user can "fork" an example and modify it. I think it would be extraordinary if for an OpenGL example - run it, and run some commands with it (such as press and hold w key for 5 seconds) record it and show it to the user. I think something like this would have to be queued but I think it could provide an amazing new experience to people. I write something simple - then you fork it add some stuff - then I fork it etc etc.