C and C++ Source Code Snippets

Welcome to Cprogramming.com's programming code snippet repository. Peruse the archives or add your own snippets for others to use! (Check the following link a better definition of a snippet)

Sort by clicking on any of the headers.

SnippetAuthorLanguagePlatformRating (votes)
Distanceprog-bman C++ANSI5.5 (185)
Calculates 1 variable statisticsPaul Kennedy C++ANSI2.3 (33)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI7.0 (764)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.7 (241)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.5 (197)
Calculates the closest point to a segmentAdrián Deccico C or C++ANSI5.0 (157)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.6 (229)
Checking for powers of twoWebmaster C or C++ANSI5.7 (323)
Template Calculatorprog-bman C++ANSI5.4 (330)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (445)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.7 (446)
A game setup for DirectXPaul D C or C++ANSI5.5 (282)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (667)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI2.5 (34)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.1 (180)
Creating, printing and free linked listsSyed Rafey Husain CANSI2.9 (35)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI5.3 (87)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI8.2 (324)
Another merge sort of integer listManoj CANSI2.8 (36)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI2.9 (37)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.6 (12)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (35)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.3 (1237)
Print variables with file and line number for debuggingmike lear C++ANSI2.7 (36)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.5 (52)
string to bitstring, bitstring to stringEsa Karjalainen CANSI4.2 (46)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.3 (123)
Convert an integer into binary representationElabed Soufiane CANSI3.2 (42)
Generate a spiral matrix for n elementsRaza C or C++ANSI4.4 (54)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI3.0 (39)
Next 30
Previous 30

Add a snippet!