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 (184)
Calculates 1 variable statisticsPaul Kennedy C++ANSI5.8 (9)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI7.6 (387)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.6 (238)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI6.1 (171)
Calculates the closest point to a segmentAdrián Deccico C or C++ANSI5.7 (133)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.1 (202)
Checking for powers of twoWebmaster C or C++ANSI6.5 (269)
Template Calculatorprog-bman C++ANSI6.1 (276)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.7 (347)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.6 (358)
A game setup for DirectXPaul D C or C++ANSI6.3 (231)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI6.3 (569)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI6.2 (10)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.8 (156)
Creating, printing and free linked listsSyed Rafey Husain CANSI6.4 (8)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI6.6 (36)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI7.8 (50)
Another merge sort of integer listManoj CANSI6.3 (11)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI6.3 (12)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.3 (11)
Find the minimum distance between two linesGiacomo C or C++ANSI7.2 (11)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.6 (533)
Print variables with file and line number for debuggingmike lear C++ANSI6.1 (12)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI7.2 (25)
string to bitstring, bitstring to stringEsa Karjalainen CANSI7.4 (18)
Calandar generator printing a full calendar for any yearJoe C++ANSI7.4 (40)
Convert an integer into binary representationElabed Soufiane CANSI6.5 (17)
Generate a spiral matrix for n elementsRaza C or C++ANSI6.8 (25)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.9 (14)
Next 30
Previous 30

Add a snippet!