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)
GetLastError error lookup toolKen Fitlike CWindows5.2 (209)
A singly linked list with a sentinel implementationyzb3 CANSI4.9 (21)
Useful string functionsyzb3 CANSI5.7 (143)
Pascals Triangle Using Combination Function of IndicesSHINE AIYYAPPAN CANSI6.2 (501)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI2.9 (37)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (35)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (668)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.5 (52)
Simple swapping heapsortyzb3 C or C++ANSI5.2 (160)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI4.9 (100)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.2 (76)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows5.0 (96)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple5.2 (61)
This C code assigns codes to a maximum of 10 charsAbhishek H.Dwivedi C or C++Windows3.1 (34)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI3.3 (41)
A game setup for DirectXPaul D C or C++ANSI5.4 (285)
This C code recursively sorts an array of upto 20Abhishek H.Dwivedi C or C++ANSI5.3 (236)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.7 (241)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI5.5 (159)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (865)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.1 (180)
Calculates the closest point to a segmentAdrián Deccico C or C++ANSI5.0 (158)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.5 (200)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.5 (477)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.3 (166)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (373)
One line swap of integersabhilash C or C++ANSI5.4 (199)
A very simple frames per second functionJeff Verkoeyen C or C++Windows5.3 (228)
Macro to swap nibble of BYTET Sailesh C or C++ANSI3.4 (42)
Next 30
Previous 30

Add a snippet!