268 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for jnbgames.dev

The program below is written in **C** and is used to convert numbers to words. These operations are beneficial during the development of word processing applications. The program takes the **input** file that contains the number and **outputs** the results in an output file. Let me know if you find …

Member Avatar for Dani
0
470
Member Avatar for jnbgames.dev

The program below is written in C and creates a stack that holds the values of a maze. This structure is beneficial during the development of a desktop game that uses a maze. Let me know if you find the code below helpful and if you have any additional suggestions:

Member Avatar for Dani
1
332
Member Avatar for jnbgames.dev

The program below is written in C and is used to perform fast number operations. These operations are beneficial during the development of spreadsheet applications. Let me know if you find the code below helpful and if you have any additional suggestions:

Member Avatar for rproffitt
0
245
Member Avatar for harshchandra

This is a simple archery Game developed in C language . The aim of the game is to shoot the balloons and score as much points as you can . The game have three levels. Platform used is Turbo C++ IDE . Standard Graphics.h functions are used.

Member Avatar for 26_Anuja
0
4K
Member Avatar for thomasdoejr

Write a program using for loops to produce an R by C rectangle, where R and C are provided by the user. The following are the triangles for different values of R and C. R is the number of rows and C is the number of columns

Member Avatar for rproffitt
0
348
Member Avatar for majestic0110

Hi all, here is a small program I have worked on over these last two days, I have submitted it in the hopes of some constructive criticism and suggestions (please be kind, this is one of my earlier C projects lol). This is a small console application that simulates a …

Member Avatar for Baneeishaque
1
10K
Member Avatar for praneeth_gunda

This Program implements the Predictive Parsing Of the grammar E->E+T/T F->F*T/F F->id(Identifier)

Member Avatar for yesim
1
27K
Member Avatar for chandrabhanu

Above program takes input of coefficient and power separately of 2 different polynomials add them up to a new polynomial.It is successfully compiled and executed in DEV CPP as C file.It Turbo C compiler add void before main function to avoid warning messages.

Member Avatar for Nithesh_1
0
49K
Member Avatar for andrewll2

This snippet converts a CIDR notated IP address to a range of IP addresses in decimal, dotted notation. Eg.: 192.168.1.255/31 => 192.168.1.254 - 192.168.1.255

Member Avatar for JamesCherrill
0
4K
Member Avatar for Graphix

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for C! It uses a words file, on the bottom of this post you will see a small example of a few words. You can …

Member Avatar for Anish_4
0
4K
Member Avatar for directorabbey

void Halt (); void Reply (const char * num,uint8_t stat); { this is the error message for this code 7|error: 'uint8_t' has not been declared 9|error: expected unqualified-id before '{' token

Member Avatar for directorabbey
0
274
Member Avatar for tyrantbrian

Following is a matrix multiplication code written in MPI (Message Passing Interface) which could be run on CPU cluster for parallel processing. This has been successfully tested with two square matrices, each of the size 1500*1500.

Member Avatar for Gustavo_4
2
19K
Member Avatar for Luckychap

A simple graphical year calendar. Compiler: Turbo C In main current year is set manually, for more generic way use date function to get current year.

Member Avatar for santlaha
0
383
Member Avatar for ayeswarya

[CODE]struct PCB* handleProcessArrival_PP(struct PCB *processhead,struct PCB *processtail,struct PCB *currProcess,struct PCB *newProcess,int currTime){ if(currProcess==NULL){ newProcess->executionStartTime = currTime; newProcess->executionEndTime = currTime+newProcess->totalBurstTime; newProcess->remainingBurstTime = newProcess->totalBurstTime; if(newProcess->processID==processhead->processID){ processhead= newProcess->next; printf("processhead in case 1 %d \n",processhead->processID); } currProcess=newProcess; printf("***current process = new process%d \n",currProcess->processID); contents(processhead); return currProcess; //return processhead; } if (currProcess->processID !=0){ contents(processhead); if(currProcess->processPriority>newProcess->processPriority){//new …

Member Avatar for rubberman
-1
3K
Member Avatar for Dave Sinkula

Many times [inlinecode]strtok[/inlinecode] is recommended for parsing a string; I don't care for [inlinecode]strtok[/inlinecode]. Why? [list][*]It modifies the incoming string, so it cannot be used with string literals or other constant strings. [*]The identity of the delimiting character is lost. [*]It uses a static buffer while parsing, so it's not …

Member Avatar for anti_neoliberal
0
10K
Member Avatar for dileepkumar235

Login functionality in C-language : Here the user enters the user id and password. The entered user id and password will be compared with the stored ones and user will be authenticated. While user enters password, characters should not be displayed on the screen. user id comparison must be case …

Member Avatar for Tanmay_1
0
4K
Member Avatar for vegaseat

The bubble sort is slow and I thought it would be interesting to visualize the progress as it sorts an array of integers.

Member Avatar for David_50
5
745
Member Avatar for jephthah

too many new and intermediate users of C attempt to use the command [icode]fflush(stdin)[/icode] to "flush the input buffer". this is patently wrong. the rule is (and click if you don't believe me) : [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351"]NEVER [/URL][URL="http://answers.yahoo.com/question/index?qid=20071013052534AAuxWmW"]USE [/URL][URL="http://www.gidnetwork.com/b-57.html"]"FFLUSH()"[/URL] [URL="http://www.linuxforums.org/forum/linux-programming-scripting/41287-problem-fflush-stdin-function.html"]ON [/URL][URL="http://www.it.usyd.edu.au/~dasymond/mirror/c-faq/stdio/gets_flush2.html"]INPUT [/URL][URL="http://www.cplusplus.com/forum/general/6554/"]STREAMS [/URL][URL="http://c-faq.com/stdio/stdinflush.html"]SUCH [/URL][URL="http://gcc.gnu.org/ml/gcc-help/2009-01/msg00287.html"]AS [/URL][URL="http://www.dreamincode.net/forums/showtopic45833.htm"]"STDIN" [/URL] here is one method of properly …

Member Avatar for David_50
0
6K
Member Avatar for vegaseat

I have joined the thousands who have done it before, and have compared a number of sorting routines. The sorting is done on the same random-integer arrays. No surprises, quicksort wins this simple comparison hands down. There are clever combinations of sorting routines that are faster, like the snippet by …

Member Avatar for vegaseat
2
253
Member Avatar for anurag_pareek

it is a simple program but the beuty lies in its shortness it is written in least line as possible By :- Anurag Pareek

Member Avatar for Indra_1
0
235
Member Avatar for harshchandra
Member Avatar for athlon32

This is just a little example of howto make a Gtk+ application go fullscreen. This is really useful in game programming. Please rate/comment/report errors :icon_mrgreen:

Member Avatar for Stefan_4
0
3K
Member Avatar for L7Sqr

Often times it is useful to instrument a program you do not have the source to in an attempt to learn more about it. This can be for debugging purposes, blackbox testing, or for providing alternate versions of common functions/libraries (to name a few). On Linux, there is a very …

2
1K
Member Avatar for zegarnek

Hi, I am just playing with C code in the console under Linux. In the old times a fair bit of code was written for a console; programs were operating in text mode, creating menues was quite a fun. I coded very simple c routine to print a strings of …

Member Avatar for N1GHTS
1
3K
Member Avatar for lazylibran82
Member Avatar for bumsfeld

A simple program to show you how to create a table of Fahrenheit and Celsius values using a for loop. You may be able to learn from this code.

Member Avatar for rubberman
1
279
Member Avatar for Jaks_maths

This Program prints the numbers in given array(Row-Major Order) in Spiral order. Ex: Order Is 3*4 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Spiral Order Of Matrix is 11 12 13 14 18 22 26 25 24 23 19 15 16 …

Member Avatar for rubberman
0
296
Member Avatar for NEMO_1990_2007

The greatest common divisor of integers x and y is the largest integer that evenly divides both x and y. Write a recursive method Gcd that returns the greatest common divisor of x and y. The Gcd of x and y is defined recursively as follows: If y is equal …

Member Avatar for David W
0
540
Member Avatar for tux4life

One of the things which attracted my attention was that there are often newbies asking how to create a password program in C/C++, often they don't succeed, well here's my response, you can use it for any purpose you want, one thing you'll have to keep in mind is that …

Member Avatar for Remy1990
0
8K
Member Avatar for mayankjoin
Member Avatar for richieking

This is a basic CPP sleep fuction. As you can see CPP libs do not come with a time sleep/wait fuction to use in your code/loop. So due to boring jurney to Saint Petersburg, i decided to write something/code to give anyone who has been wondering why CPP does not …

Member Avatar for deceptikon
0
2K
Member Avatar for vegaseat

This is an example of a singly linked list allowing you to enter a number of names and associated ages. The twist is that the names are inserted into the list in ascending order. When the list is displayed, it is already sorted by name. Note: This is not an …

Member Avatar for Ancient Dragon
1
469
Member Avatar for deepakps

this is a small graphical program in c....which gives you a clear discription about what a graphics can do in c..(a simple one)

Member Avatar for Deepak_17
0
175
Member Avatar for D33wakar
0
349
Member Avatar for D33wakar

This is a simple echo server that I've written while learning sockets programming. Compile the server and run it. You can connect to it using telnet like this: telnet localhost 1337 Disconnect the client by typing "/quit" without quotes.

0
388
Member Avatar for ~s.o.s~

Here is a simple implementation of implementing a simple Left trim (ltrim) and Right trim(rtim) of unwanted characters from a C style string. (null terminated strings). Doesn't suffer the overheads of the memmove implementation in which the worst case scenario (a string containing all junk characters) is approx. N^2 / …

Member Avatar for Ancient Dragon
0
3K
Member Avatar for emil_ham

This simulator works for: 1. First Come First Serve (FCFS) 2. Round Robin (RROB) 3. Priority (PRIO) 4. Longest Job First (LJF) 5. Shortest Job First (SJF) algorithms. The program is written for gcc linux compiler. In input file a sequence of processes coming to the systems included, where also …

Member Avatar for ElGauchoUTn
1
2K
Member Avatar for vegaseat

In Las Vegas random numbers move billions of Dollars in and out of gamblers' pockets. For the mildly inquisitive here is a test of three simple generators.

Member Avatar for rubberman
1
6K
Member Avatar for Adak

Demonstrates the Right Hand Rule maze solving algorithm, with some sweet console colors and text display and erasing, in Windows. Note that if the Start is moved away from all the walls in the maze, the right hand rule fails, circling endlessly. Also, a similar failure happens if the Start …

0
3K
Member Avatar for jai_steave
Member Avatar for <M/>

This function takes a string and an output buffer and a desired width. It then copies the string to the buffer, inserting a new line character when a certain line length is reached. If the end of the line is in the middle of a word, it will backtrack along …

Member Avatar for <M/>
0
388
Member Avatar for Raghuvamshi

Quick sort is a faster way to sort a given array by recursion The algorithm goes like this: it first takes some index element and seperates all elements lesser than this with larger numbers then places this element in right place and does the same thing with all other

Member Avatar for hhhadvani00
0
898
Member Avatar for deceptikon

I was going to post this in a thread, but it turned into something a bit more serious and may be useful as a code snippet. The code shows three files: * menu.h: The header file for the menu library. * menu.c: Implementation of the menu library functions. * main.c: …

Member Avatar for deceptikon
3
591
Member Avatar for vegaseat

So you want to find out which day of the week you were born. Well at least some of us do. I actually wrote this program because my whole family was born on Sundays, and my friends didn't believe it! An oldie but goodie, moved from DeSmet C to Turbo …

Member Avatar for jnawrocki
3
1K
Member Avatar for Dave Sinkula

Finding some text and replacing it with new text within a C string can be a little trickier than expected. Here is what I had come up with one day.

Member Avatar for deceptikon
0
1K
Member Avatar for Nutster

Recently, I saw somebody start a "Deal or No Deal" game in the Posting Games section. This got me thinking of writing a program to actually play the game based on the rules of the show. So I spent a couple of hours writing this in ANSI-C. I probably should …

Member Avatar for Nutster
0
343
Member Avatar for ashine80
Member Avatar for nitin1

#include<iostream> #include<algorithm> using namespace std; #define MAX 10000000 #include<stdlib.h> #include<string.h> char s[MAX]; int p[MAX]; int bucket[MAX],nbucket[MAX]; struct suffix { int idx; }pos[MAX]; int H=0; bool cmp(struct suffix i,struct suffix j) { if(H==0) { return s[i.idx]<s[j.idx]; } else { if(bucket[i.idx]==bucket[j.idx]) { return bucket[i.idx+H]<bucket[j.idx+H]; } else { return bucket[i.idx]<bucket[j.idx]; } } } …

Member Avatar for deceptikon
0
617
Member Avatar for NicAx64

Circuit, [Circuit Diagram](https://picasaweb.google.com/116591322380497799116/December52012#) Video: [Video](http://www.youtube.com/watch?v=qGoM_ydAtBc)

0
489
Member Avatar for chandrabhanu

This program in C finds 2 Longest common subsequence of 2 given strings(say X and Y),entered without any space on the screen individually,altering X and Y strings.I compiled and executed this above program successfully in Dev Cpp compiler as a C file(not a c++ file).

Member Avatar for hahahahohoho
-1
270

The End.