2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for anurag_pareek

This is a simple balloon shooting game made in C language. In this game, there are number of balloons, a bow and arrows for shooting the balloons. The balloons rise from the lower portion of the screen. The bow is put on left side which can move up and down. …

Member Avatar for luna19
0
984
Member Avatar for johnroach1985

This program searches the given txt file.And tells you how many there are. Just a reminder don't forget to put the searced txt file in C: or change it accordingly for more info or questions [email]Silver.Lost.Raven@gmail.com[/email] have fun!!

0
546
Member Avatar for Dave Sinkula

Obtaining user input can be done in many surprisingly different ways. This code is somewhere in the middle: safer than [inlinecode]scanf("%d", &n)[/inlinecode], but not bulletproof. It is meant to be a simple but relatively safe demonstration. The function [inlinecode]mygeti[/inlinecode] reads user input from the stdin into a string using [inlinecode]fgets[/inlinecode]. …

0
1K
Member Avatar for Dave Sinkula

This snippet shows how to use the functions [inlinecode]time[/inlinecode], [inlinecode]localtime[/inlinecode], and [inlinecode]strftimetime[/inlinecode] to pick off only the time parts for display.

0
132
Member Avatar for Dave Sinkula

Some issues with date/time calculations. [Perhaps I ought to edit this one day and better describe it.]

0
132
Member Avatar for Dave Sinkula

To check for integer overflow, you can't simply check the [i]outcome[/i] of an operation, you need to check [i]before[/i] the operation. So how do you do that? This example checks for overflow with multiplication.

0
357
Member Avatar for Dave Sinkula

This is yet another example of reversing a string. This version modifies the original, reversing the string in place. [I]See also [url=http://www.daniweb.com/code/snippet522.html]Strings: Reversal, Part 2[/url][/I].

0
615
Member Avatar for Dave Sinkula

This problem is a typical homework question. The code presented here may contain some elements that may be a little "ahead of the game" in coursework, but it presents some of the basic elements that might be used in such an exercise.

Member Avatar for Sealteam56
0
246
Member Avatar for vegaseat

A common way to represent an inventory is with a list of tuples. Each tuple represents the item name and the item count. You can sort this inventory list by item name or item count. Here is an example to pick a sort key. It's your summer job to run …

1
586
Member Avatar for vegaseat

Where you ever curious what the most common letter is in a typical text file? Just another question to ask a friend. The answer is right here in this tiny code snippet. The program converts the text to all lower case letters, and then list them out alphabetically showing the …

Member Avatar for programtrav
0
189
Member Avatar for rhenerlau

This code uses field level validation to check for data in fields in an Access form, and instead of using message boxes (as the "Validation Rule" and "Validation Text" properties of a field (in the table design window) do, it turns the associated label and control (textbox/listbox/combobox) background color to …

1
127
Member Avatar for rhenerlau

Place the file with part one of the code on the server. This part of the code gets placed in a batch file (text file with the extension *.BAT) and placed on each client's machine. Again, you will need to change the paths used to the real paths on your …

0
169
Member Avatar for JRED

This code snippet will attempt to show newbies to php how to connect and retrieve data from a PostgreSQL Database Server using PHP.

Member Avatar for Troy
0
194
Member Avatar for corewizard
Member Avatar for Drew

Learn how to loop anything you want sertain number of times. In this example im gonna show you a simple next and loop that changes the font size.

0
95
Member Avatar for Drew

This is a neat little script that will tell you how many active users you have on your site. You do need a webhost that supports the global.asa file! Most free hosts dont. [B]Code From: [URL="http://http://www.iportalx.net"]http://www.iportalx.net[/URL][/B]

0
140
Member Avatar for pankleks

It is a small two-in-one calculator that can work as a regular or RPN calculator, selected by a RPN checkbox. It has a four level stack similar to the HP 48 calculator made from four Tmemos. This code shows you how to make visual effects(RPN stack) from existing delphi components. …

0
197
Member Avatar for ShawnCplus

This is the first program I wrote, well besides Hello world. I put about a lot of hours into this code, it started as a divisional calculator than i evolved it so it would ask your name and calculate your average and i was messing around with the system ("") …

Member Avatar for ShawnCplus
0
889
Member Avatar for aj.wh.ca

This is a bit more tough than it sounds. well some one gave me this problem and I found this tricky not until I used recursion.

0
790
Member Avatar for Tight_Coder_Ex

There are numerous calls to Win32 API that return detailed information as to failure via GetLastError (). I've devised a method by which to get the textual information corresponding to error and the address of the call that caused the violation. If GetLastError () returns null, then it can serve …

0
324
Member Avatar for vegaseat

The module datetime allows you to call several functions that can do computation with dates and times. How many days since my birth? How many days till Xmas? What's the date 77 days from now? The code snippet should give you a flavor, enough to explore on your own.

2
823
Member Avatar for vegaseat

Many of the code samples on the internet are written in Turbo C. The clrscr() function litters these samples, and even to this day people want to wipe your screen. You can use system("CLS"), but that uses a DOS command. DOS commands are with us only at the whim of …

1
741
Member Avatar for vegaseat

Quick and dirty way to change your console program colors using DOS command "Color BackgroundForeground" where Background is hex 0 = black to F = white, dito for Foreground.

1
291
Member Avatar for Scribbller
Member Avatar for vegaseat

The wxPython library allows Python to create Windows GUI programs. Here is a look at the listbox component. Click a button to load the listbox with names, select the name by clicking on it on the list, and display it in the title bar of the window frame. Another button …

Member Avatar for vegaseat
2
3K
Member Avatar for vegaseat

This program uses WinApi function SetPixel() to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x) along a y-axis centered on the console screen. Make sure that gdi32.lib is included in the libraries to be linked.

Member Avatar for brale
2
305
Member Avatar for vegaseat

Just a simple way to separate the words contained in a sentence. As an option you can store the words in a vector. If you are not familiar with a vector, use an array instead.

0
192
Member Avatar for vegaseat

I look at BCX-basic as a modernized qbasic. This simple code creates a Windows GUI program that plays a midi instrumental music file. To keep it simple, the file it looks for is "TheRose.mid" file. If you don't have this file, you have the option of editing the code, or …

Member Avatar for billzilla
0
222
Member Avatar for vegaseat

Shows how to connect a button onclick event to a javascript function to change the background color of the document. Just cut and paste the code into Notepad or other editor, save as BGchanger.htm and run it on your browser.

Member Avatar for Mohan0704
0
191
Member Avatar for vegaseat

Remember the Spirograph? It used geared circles to create some rather artistic geometric designs. This program uses triangles to follow in the Spirograph's foot steps. The math is rather simple, just a couple of sine and cosine functions, also the ubiquitous for loops, everything wrapped up in the using() statement. …

0
174
Member Avatar for Comatose
Member Avatar for willdove
0
314
Member Avatar for vegaseat

The set is an unordered collection of unique hashable elements. All the elements/items in a set are treated as keys. There are several functions that compare two sets. Right now, I will just give you a taste ...

3
334
Member Avatar for Narue

A fairly complete implementation to provide another perspective on a seemingly simple program.

Member Avatar for Ene Uran
0
146
Member Avatar for TkTkorrovi

A very rudimentary more, press enter to view next screenful of text, like with print command in ed text editor.

0
104
Member Avatar for TkTkorrovi

Similar to cat in unix textutils. You can actually edit files with these. Remember that ctrl-z sends end-of-file in windows, and ctrl-d in linux.

Member Avatar for Dani
0
105
Member Avatar for TkTkorrovi

Text fragment extractor (usage: fragment /pattern/[n] [/pattern/[n]] file), similar to the print command in ed and vi, with pattern range. If the second pattern is omitted, prints to the end of file. Use quotation marks when there are spaces in the argument. Finds the first pattern, then the second pattern, …

0
130
Member Avatar for vegaseat

The code shows you how to create a window without a titlebar that can be dragged with the mouse. Set the FormStyle property to fsStayOnTop. The form contains a small 18 button calculator. When you create the form and calculator components, try to make it tiny, it is cute that …

0
322
Member Avatar for vegaseat

Using wxPython and the Boa Constructor, a VB/Delphi like IDE and Visual Builder, this little calculator was a breeze to make. Boa did 90% of the code generation, and I simply added code to each button click event to make the calculations work. I wish every project would go that …

Member Avatar for vegaseat
1
486
Member Avatar for Mahen

Chargen is a program created entirely by mahen of Mauritius. The simple task of Chargen is to generate characters, but the most important aspect of this particular program is it's abillity to process user input. Due to the way the program was programmed, any input that the user will make …

0
376
Member Avatar for Siersan

Unlike a balanced skip list, a probabilistic skip list uses random numbers to determine the height of each node rather than deterministic logic. The only real advantage of using a linked structure instead of an array based structure is in code maintainability.

0
106
Member Avatar for Siersan

Array based skip lists are a pain to work with. They are error prone and difficult to follow. Worse, they are difficult to extend so that the data structure is deterministic rather than probabilistic (a desirable property). The following implementation uses a linked structure instead of arrays for the levels.

0
147
Member Avatar for VSBrown

A program that reads in two integers and determines an prints if the first is a multiple of the second.

0
197
Member Avatar for VSBrown

A program used to calculate each employee's pay based on that employee's paycode.

Member Avatar for freckman1981
0
2K
Member Avatar for VSBrown

A program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers.

0
200
Member Avatar for VSBrown

Find all Pythagorean triples for side1, side2 and hypotenuse in which all sides are no larger than 500. Use a triple nested for loop that tries all possibilites.

0
2K
Member Avatar for VSBrown

A program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum,product,difference, and quotient of the two numbers.

0
464
Member Avatar for VSBrown
Member Avatar for Ene Uran
0
188
Member Avatar for VSBrown

Uses the string comparision functions and the techniques for sorting arrays to alphabetize a list of strings. Uses the names of 10 or 15 towns in your area as data for the program.

0
992
Member Avatar for VSBrown

A test program that will call the PROC findGCD, passing in the integer values input by the user and then it will display the results to the screen.

0
637
Member Avatar for VSBrown

A program that will test the Nonrecursive Factorial procedure using a value passed in by the program user and will also do a time comparision of the Nonrecursive and Recursive Factorial functions.

0
598

The End.