Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Everything / Languages / C

C

C

Great Reads

by KarstenK
Some toughts whether to prefer Objective-C or Swift.
by Bartlomiej Filipek
Include Guards, Pragma Once, Predeclarations and other hints that might be useful when dealing with includes.
by Sergeant Kolja
This is an alternative for "Memory leak detection for WinCE".
by Cindy Potvin
Many options of the .LESS CSS parser can be set directly from the Web.config file, but many of them are not clearly described. Here is my attempt to document them.

Latest Articles

by KarstenK
Some toughts whether to prefer Objective-C or Swift.
by Bartlomiej Filipek
Include Guards, Pragma Once, Predeclarations and other hints that might be useful when dealing with includes.
by Sergeant Kolja
This is an alternative for "Memory leak detection for WinCE".
by Cindy Potvin
Many options of the .LESS CSS parser can be set directly from the Web.config file, but many of them are not clearly described. Here is my attempt to document them.

All Articles

Sort by Score

C 

by KarstenK
Some toughts whether to prefer Objective-C or Swift.
by Mike Meinz
Describes an algorithm to ignore spurious ultrasonic sensor readings.
by Ph. Jounin
A C-replacement for MessageBox
by Ohmu
A step-by-step Guide to getting a pure code application template.
by AshakiranBhatter
ScreensSaver through fullscreen mode using Win32 APIs in C.
by Ritesh_Singh
C++ code to connect/access DB2 database using DB2 call level interface(CLI)
by Arthur Caputo
Tutorial on setting a false transparency onto your button's edges.
by Michael Gledhill
How to add an fade-in message to your iPhone app in 5 minutes
by Santosh Sharma (go2santosh)
Finally iOS developers get a new programming language as advanced as C# and Java
by Arthur V. Ratz
This tip/trick introduces the basic ideas on how to avoid memory mismatched allocation/deallocation issues detected by Intel® Inspector XE for Visual Studio 2015
by Abed AlSayed
AlSayed ColorBar is a TrackBar best for professional color picker, like the one used in Adobe Photoshop.
by Jigar_Patel
Amazon S3 lib for uploading file in C++ using VS2010
by cruppstahl
Describes algorithms for integer compression, introduces a few libraries and shows how to use them
by Thinira
In this tip, we will discuss how to setup Angular 2.0 in Visual Studio and write a very basic “Todo” application.
by zvx
An introduction to writing IOCP network servers
by Steffen Ploetz
Step-by-step instructions and source code snippets for inserting a bitmap (or a section of it) into an icon image.
by Steffen Ploetz
Automatically Disappearing Dialog
by Zebedee Mason
Or why not both? This shows how.
by Laurie Stearn
Dialogex with Listbox to manipulate long paths in Windows
by jafarmlp
Introduction...
by Daniel Ramnath
Breaking weak RSA with C++ & GMPXX library
by BEmbedded
This article discusses 'C' code used to control a Newhaven OLED in 4-bit mode. It is a MBLABX project.
by Eric Z (Jing)
This tip introduces struct hack and compares it with several implementation alternatives.
by Ullas_Krishnan
How create a Splash Screen in C++ Program (TurboC) in DOS Mode..
by Lars P.Wadefalk
I have sometimes wondered if the 'with' statement would work in C/C++, just like in pascal. Meaning that it would in it's nearest scope automatically recognize class/struct members for the ones mentioned with a . or maybe -> operator.Maybe something like:TestClass* tc;float...
by Shao Voon Wong
Never test for NaN by comparing it with NaN literal
by Askar Azhibaev
Calculating the pi number faster using a simple formula
by CathalMF
Describes with an example of how you can call C#.NET methods from unmanaged C++ code.
by Abdallah Al-Dalleh
How to handle post data coming inside an HTTP POST request
by Taehoon Kim 1004
Capture program using GDI
by Ghosuwa Wogomon
An in-depth explanation of correct bracket placement and why...
by Tejashwi Kalp Taru
Ever wanted to change the Windows Aero color without restarting the DWM?
by PJ Arends
I have seen many different ways to check if the computer has an active internet connection. The best one, IMO, is to check for the presence of the default route in the IP forwarding table that is maintained by windows. This can be checked by using GetIPForwardTable function found in the...
by Melih Mucuk
Check whether location service enabled for your app.
by _Ravikant Tiwari_
This program will demonstrate the process of injecting code into already running processes. Here we have choosen to inject into Explorer
by _Ravikant Tiwari_
Code Injection - A Generic Approach for 32bit and 64bit Versions
by David A. Gray
While you can often get away with ignoring compiler warnings, failing to at least scan them can bite hard!
by pi19404
This article describes the method to cross compile C/C++ library for Android OS
by leon de boer
Implementation of connected component labeling and subsequent vectorization.
by perilbrain
A very simple trick to assist you in eradicating out manual file name entries.
by CPallini
A simple algorithm for counting occurrences of symbols in files
by Florin Gherghel
How to create a BOTTOMMOST window (Win32 and .NET).
by Volirvag Yexela
This tip suggests the way of launching a process with Medium IL from the process with High IL.
by Melih Mucuk
Creating a WCF Service with JSON data for use on iOS
by Philipp Sch
How to use an IStream-Interface with FFmpeg
by Dennis E White
How to create delegates in Objective-C
by araud
Did you ever want to know where most of the memory is consumed? Whether it leaks or just gets allocated too much. This home brew memory tracker is yet another bicycle that you will be able to tune for your needs.
by Kerem Kat
Compile and run CUDA 3.2 projects from VS2010 in 9 easy steps
by Alex Culea
Shows how to create a window that behaves like a context menu
by José Cintra
An example of how to interact with the user through the keypad, LCD and Buzzer
by Member 7961821
Life debug plug-in of non debugable host
by Mukit, Ataul
This not so useful tip tells you how to declare a reference for a two dimensional array without needing to use typecasting.
by kooyou
The second form is wrong. A two dimensional pointer does not equal to a two dimensional array. But you can use an one dimensional pointer to reference the two dimensional array.int arr[1][20];int *pTwoDem=(int*)arr;Now you can use *(pTwoDem+10) to replace arr[0][10].
by david pretham
Windows Native API application
by Pranay Rana
Design TypeDataSet from Storedprocedure using temptable
by pasztorpisti
An advice to make your DLL interface more attractive and easier-to-maintain even in cross-platform projects
by mbue
switch ... case statement for strings
by Ahmed Elkafrawy
An easy way to simulate keyboard press & release keys to another application
by Mircea Neacsu
Source code organization suggestion
by Haftmann, Henrik
12 years too late but now it works: A replacement driver for giveio and dlportio for 64-bit Windows
by Amogh Natu
This tip shows how you can add scrolling to a view in iOS to allow multiple elements on the screen that won't fit in one screen.
by Vinayaka Krishna Shenoy
I explored a bit more on Entity framework,during last week of 2009 and here goes my observations on how to extend the Entity Framework functionality if you want to customize the normal/ideal flow of Entity framework execution engine.1) OnContextCreatedBy default a declaration of this...
by itsdkg
This tip explains the usage of arrays for creating Fast binary search trees.
by YvesDaoust
Yet another home-made implementation of the floor function
by jurhas
Solving graph on linear time
by CPallini
Fast integer square root computation in 8051 assembly
by Alexey Shtykov
The thing that could generate pseudo random numbers faster than standard library does
by Jacob F. W.
Here I present an improved version of the Circular Shift Operations
by Issam Lahlali
Some feedback to avoid common mistakes when porting a .NET application to Mac OSX
by mef526
Finding a substring is trivial, but is it a word?
by stevic
Finding Fibonacci sequence can be done by a simple logic, but we can solve it too with a Math formula
by Artem Moroz
A story on how memory leak can appear from seeminghly nowhere
by Tejashwi Kalp Taru
When we have to scroll some text in the dialog box with a background image, you can see flicker. Here's the technique of double buffer to solve this problem
by Member 16179004
Capture Enter key in edit control with no dialog box and no subclass.
by AbdulRahman A. Badry
Alter your display gamma-ramp to correct & calibrate it
by ergohack
System.Data.SQLite is great, but was missing some BLOB support. Switching to the native source project was easier than expected and provided significant functionality benefits.
by Mohammad_Hamad
Using the Function Pointer inside C struct
by m_sylvain
This tip shows how to build an FxEngine plugin to stream video data from a webcam
by Arun Maiya
How to setup GCC cross compiler in Windows to generate Linux binaries
by Southmountain
Gems for typedef and namespace in C
by murtaza dhari
A generic dropdown control using LINQ to SQL and Entities using Reflection
by Mike (Prof. Chuck)
Generic EventHandler/EventArgs with a generic implicit cast operator
by Paul Brower
This tip will allow you to return the value from column X, where column Y matches your filter
by Loay Al Lusi
Genetic Algorithm is used to search for maximum/minimum value of a given function using the concept of chromes and genes.
by Abhishek Nandy
Smartwatch Development with pebble
by Member 11246861
Within LAN, laptop gets signals from microcomputer and microcontroller using TCP/IP and SPI
by pasztorpisti
How to open a console in a non-console C/C++ application or DLL and make printf/scanf work (stdin/stdout/stderr related functions)
by Dave Cross
I just use OutputDebugString() and Sysinternals' DebugView.exe.
by Jaime Olivares
Plain old console output is still a valuable debugging tool, even when used in a GUI application.There are many tools here in CP that can be combined with console output like:CConsole - a simple console for debug output[^]Creating a console for your MFC app's debug output[^]You can use...
by trident99
GT is a compact, efficient, and customizable graphical user interface (GUI) library for the Windows environment.
by Steffen Ploetz
A solution for: If the toolbar is created button by button with single TB_ADDBUTTONS calls, the width of the separators is not calculated correctly.
by CPallini
Simple approach to heap data structure and heapsort, using C and Lua
by Dharmateja Challa
This article is about generating random data using Trusted Platform Module in Windows 10 and testing its randomness using dieharder test suite.
by Southmountain
Some tips on how to compile legacy Win32 programs in Visual Studio 2019 - may save you few hours to figure out why
by Lai Taiyu
How to do simple image binarization?
by Itai Basel
A macro that gets current function's return type on visual C++
by ColleagueRiley
A tutorial that explains how to setup and handle clipboard copying and pasting for X11, WinAPI, and Cocoa.
by ColleagueRiley
A tutorial that explains how to handle Drag 'n Drop events for X11.
by Cloud Hsu
How to implement Queue in Objective-C
by Cloud Hsu
Stack implementation for Objective-C.
by Bipin Paul
Implementation of Contact Us Page using ASP.NET MVC pattern
by Tecfield
This post shows how to make a callback to C# from C/C++
by Lai Taiyu
How to make a clear color image (Histogram Equalization)?
by Lai Taiyu
How to make a clear gray image (Histogram Equalization)?
by Tiago Cavalcante Trindade
How to put color in Python, C, C++, C#, Java and batch on the Windows console
by Steffen Ploetz
My best practice approach to change the image of a toolbar button
by reachmeviz
This article explains how to map source code & assembly for easy debugging in Solaris OS.
by YoungJin Shin
How to wake up a PC using waitable timer
by Marc Clifton
Each function should answer "how-what-why."
by ThatsAlok
Describing various method to zeroing the buffer in memory
by trotwa
char szTest[128] = { 0 };;)
by YvesDaoust
What about this, using SSE2 assembly (32 bits):void Zero(void* Buffer, int Count){ char* Cur= (char*)Buffer; char* End= (char*)Buffer + Count; // Clear the initial unaligned bytes while (Cur < End && (Cur - (char*)0) & 0xf) { *Cur++= 0; } // Clear...
by Jose David Pujo
I always use a home-made macro to zero my struct's and class's:#define ZEROMEMORY ZeroMemory (this, sizeof (*this))Sample1:struct S1 { double x; long i; char s[255+1]; S1 () { ZEROMEMORY; } };Sample2:class foo { private: double x[16]; char a,b,c; foo () {...
by Member 13737597
This article shows how Windows generates IP header's ID field
by Alexander Iskhakov
Creating a HTTP proxy using Play framework and WS API
by Nick Alexeev
I'm advocating for the use of Hungarian notation in microcontroller code
by Member 11246861
RaspberryPi2 master transmits to and receives from Pic24FJ64GB002 slave through I2C
by Cloud Hsu
Implement Objective-C Singleton Pattern
by Ahmed Elkafrawy
Implementation of an easy, fast, and optimized (CByte, CShort, CInt) with bits access using bit field and union
by Gregory Morse
Implementing a complete WRL native C++ XAML blank project template
by Malcolm Arthur McLean
How to implement principal component analysis clustering algorithm to perform image segmentation.
by Stefan_Lang
Header files often #include lots of other headers because other classes are being referenced. These chained includes force the compiler to repeatedly load and precompile long lists of headers over and over again. Thanks to #pragma directives or #ifdef guards this is a rather cheap operation,...
by sunhui
Integrate .NET Component to your Native MFC Application at runtime
by Stefan_Lang
When you compare a variable (a lvalue) to a constant (not a lvalue), always write the lvalue on the right hand side of the comparison.Bad example:if ( n == 5 ){ // do something}Good example:if ( 5 == n ){ // do something}This will help with your debugging in case...
by vivekshankars
Program to calculate the IRR value using C/C++ similar to the one available in Excel
by Steffen Ploetz
How to embed icons into Win32 programs without utilizing resources - useful for platforms without resource editor/resorce compiler, e.g., ReactOS. Learn the missing things about the .ico format.
by Steffen Ploetz
Check whether ReactOS is able to run OpenGL, determine a convincing IDE and get started with the OpenGL on ReactOS.
by ColleagueRiley
RGFW introduction and tutorial. RGFW is a single-header windowing framework library & lightweight GLFW alternative.
by Dharmateja Challa
Tip on how to simulate external interrupts using Atmel Studio 7 for AVR Atmega MCUs
by Leslie Godwin
The UISwitch's UIControlEventValueChanged event is pretty useless if you'd like to get a notification only when the switch value actually changes.
by Tim ONeil
Using the autoconf tool chain to add modules to the Linux kernel
by Joshua Tully
So I’m playing around with DX10 and decide to do some input work.  After much research apparently no one can decide what the best way to handle keyboard input so I’m just going to use WM_KEYDOWN/UP and store the state in a bool[] and check that in the rendering code.  Also, instead of using...
by Ghosuwa Wogomon
How to use lambda functions in C
by Tiago Cavalcante Trindade
How to use WSL, GUI on WSL and how to compile for Linux on Windows
by Nagaraj Krishnamurthy
This tip will go into the details of platform devices and their corresponding drivers in Linux
by Member 4079860
Describes a process to load/unload built in drivers under WinCE at run time to speed up development process
by KingsGambit
When we look at pointer declarations, reading from right-to-left gives a better idea about what the pointer actually points to. Consider const int * p; if we read right to left: p -> * -> int -> const. i.e. 'p is a pointer to an integer constant' rather than 'constant integer pointer' (if we...
by avinash064
It is very simple :laugh: and fun ..just divide the line before and after * , likeconst int * pconst int (before *) represent [constant integer]and *p represent a pointer add both u get a pointer pointing to a constant integer , it means u can't change value but pointer can...
by Shvetsov Evgeniy
Everything you always wanted to know about Macros but were afraid to ask
by Kai Schtrom
Win32_NetworkAdapterConfiguration WMI class in plain C and C++
by Zanga D. Dagnogo
This is a simple multiclient server chat on a Local Area Network.
by cassert24
C syntax/extensions that I somehow stumbled upon
by Asif Bahrainwala
OpenGL Compute Shader
by marcus obrien
This article compares the OO features of inheritance and function overriding in C++, C# and Java.
by Amogh Natu
This tip shows how to parse JSON response received from a web service into an NSDictionary object.
by Michael Havenga (HavenTechnik)
Get to grips with analog sensor and UART reporting with this first part.
by zvx
How to fool the C pre-processor into accepting an empty parameter to a #define
by BUR456
/*1st TARGET:Program that prints multiple bmp images*//*2nd TARGET:prints the pixel value of colors used in image*/#include#include#include#includeint main(void){ clrscr(); unsigned char color; long int Doffset, w, h; int...
by textorijum
How to SIMPLY populate TreeView from some sort of "list" variable / object / structure
by Adamanteus
Preserving overheating processor in multitasking environment
by Anshul R
Tests For a Prime Number
by Antonio Miras
Programatically set a static IP, subnet mask and gateway to an ethernet network adapter on your local machine
by Steffen Ploetz
High-end quality in text rendering concerns not only the characters, but also the character spaces - and here FreeType is not quite up to date anymore: The kerning used by FreeType is not always available (especially with newer fonts).
by Mladen Janković
Queued spinlocks implemented using inline assembly
by Michael Safyan
If you've done a regular search for API reference documentation, most likely you've come across links to very old versions of the API (e.g. links to Java 1.4.2 instead of Java 5 or Java 6), or you've probably come across plenty of links that are completely unrelated to the actual search (getting...
by Anshul R
Prime Number Testing
by Pascal Ganaye
When you search manually, you can search for every odd number that is a step of 2. If you're a bit more clever (as you are), you can use steps of 6 (2 * 3). Testing (testno+1)%6==0 is very similar to (testno % 6) = 5.You can speed up big time by having a loop that increments per steps of...
by CPallini
The question: "How can I extract 5 random cards from a deck?" (or similar), appears every now and then at the C/C++ forum.I use the following method:const int CARDS = 52;int card[CARDS]; // the 'card' array represents all of the cardsint i, deck_cards;// initializationfor (i=0;...
by Member 11246861
Raspberry master, Pic24 slave over SPI
by Malcolm Arthur McLean
These two functions load an entire text and a binary file into memory, avoiding some common pitfalls.
by Malcolm Arthur McLean
How to read and write binary data portably, including IEEE 754 floating point numbers.
by harold@talerian.com
C is still the best language for native-code development.
by Yvan Rodrigues
There is a very high virtual memory penalty if you do.
by Cloud Hsu
How to remind review in iPhone App
by David C Shepherd
A peek into the inspiration behind two cutting edge Visual Studio extensions.
by risunch
NV12 Nearest Neighbor Interpolation scaling and Bilinear Interpolation scaling.
by refusebt
RFJModel is an easy-to-use JSON loading library. In comparing with other libraries, it's much easiler and less restricted to use.
by ColleagueRiley
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
by ColleagueRiley
A tutorial that explains how to use macOS's Cocoa API in Pure-C.
by Malcolm Arthur McLean
Rotates a GIF image by the shearing method.
by Vedat Ozan Oner
Revised timer for Arduino
by Tu (Le Hong)
A scroll window that surpasses the 16-bit limit and can be hosted by a dialog.
by Amir Mohammad Nasrollahi
In this article, i consider the problem of identifying motifs in the biological sequence data sets. To solve this task, i present a new algorithm for finding patterns that just use library in C compiler and a new way to avoid using arrays search.
by Richard MacCutchan
Obscure a window or the screen and show a dialog.
by WoodyMou
Session 1: Setup SoftEther L2TP server on Amazon AWS Ubuntu
by DecodedSolutions.co.uk
This is a simple article describing how to create an add an outlook appointment to your MS Outlook Calender.
by Adrabi Abderrahim
Simple C genetic algorithm example
by Jonathan Lima
A simple key value-pair hashtable written in C
by Ghosuwa Wogomon
Detecting character encoding in just 4 lines of code
by Andres Cassagnes
A simple serial communication library, with a serial ports enumerator
by Ullas_Krishnan
This is only for students who are developing mini projects with Turbo C / C++ Compiler. This example may help you to get an idea in submitting your mini projects with stunning user interface experience with Mouse click events.
by sunhui
In this paper, we will discuss some advanced skills for ATL COM development.
by David A. Gray
Sparsely documented cause of compiler error C2143
by Pranay Rana
How to use Group By clause when joining to table Let's consider one scenario where I have two table employees (contains employee detail) and sales (contains infomation about sales done by employee).Structure of...
by josh.rendon
That conclusion is definitely wrong. Your equation expanded equals: b = (a+b) - (a-b) = a+b - a + b = 2*bFor your example a=20, b=10b = (20+10) - (20-10) = (30) - (10) = 20b = 20 + 10 - 20 + 10 = 20A counter example to disprove this: a=75, b=88b = (75+88) - (75-88) =...
by GregEllis
You can do it with some XORs:int a = 25, b = 7;a = a ^ b;b = b ^ a;a = a ^ b;Or the same thing with some shorthand to make the code even harder to read:a ^= b;b ^= a;a ^= b;
by chevu
I don't know whether these type of tips are allowed or not. But after having experience of core algorithm-base technical interview I thought I should share question I was asked in my interview.They asked me to show all methods I know to swap values of two variables.I Tried my level best...
by WebBiscuit
There is also InterlockedExchange (or your operating system's equivalent).long a = 1;long b = 2;b = InterlockedExchange(&a, b);
by dan146
swprintf_s() and sprintf_s() are additions to VC++8, and were supposedly written to tolerate formatting errors and to avoid buffer overruns. They differ from their corresponding non-safe cousins swprintf() and sprintf() by taking an extra argument (the 2nd parameter), which is the size of the...
by Eugen Podsypalnikov
Hello :)Your own description of the second parameteris different to the "original"...http://msdn.microsoft.com/en-us/library/ce3zzk1k(VS.80).aspx[^]
by qqmrichter
Overuse of #define can be ludicrous.
by Malcolm Arthur McLean
A completely portable, tiny, Unix style shell in pure ANSI C.
by D4rkTrick
Big picture of GAction, GActionGroup, GActionMap, GActionEntry, GSimpleAction and GSimpleActionGroup
by pasztorpisti
A custom implementation of the FindResource() and LoadString() functions with better error indication. Pointing the direction for those who want to learn the binary PE resource format.
by Andreas Gieriet
Short tip to show a convenient use of the lesser known xor operator
by sean_vn
The fast Walsh Hadamard transform (WHT) is done using patterns of addition and subtractions.That means it is extremely fast and also the central limit theorem applies. If you transform an array of random numbers the output numbers will have a Gaussian distribution (aka the Normal...
by parths
Create a transparent window for OpenGL so your 3D shows directly on the desktop.
by Karl Phillip
If you are looking for a true transparent window to render your 3D objects, check this thread:http://stackoverflow.com/q/4052940/176769
by Member 15078716
Unicode / Creating, Writing, Appending / a text (*.txt) file - how to do it
by Subhendu Sekhar Behera
Algorithm to find out all the Matchings and Uniquely Restricted Matchings in a Graph
by xdoukas
A tip on the implementation of Unix ucontext_t operations on Microsoft Windows.
by Clifford Nelson
The IValueConverter can be used to select a View.
by Sei Flavius
Using auto-layout to position two buttons that span the entire width of the underlying view
by Gábor Angyal
Binding C structs and functions to Kotlin is easier than you have thought!
by Melih Mucuk
Configuring and using CocoaPods on iOS projects.
by imagiro
A small class for using COM DLL modules without registering them
by JinWenQiang
Just a brief introduction of a simulator to build wireless environment
by Ksh_Sr
This tip helps you implement the nLog in conjunction with Microsoft.Extension.Logging framework in ASP.NET vNext.
by Uttam Kotdiya -India
This tip demonstrates how to use posix message for Inter Process Communication (IPC) in C#, Mono on Linux
by leon de boer
Direct Win32 API window controls that support validation (no MFC)
by Sweta Mittal
Validate whether value in string is a valid decimal number or not.
by jasper.mandos
/// /// Stuct for the ISO 8601 week date/// /// /// See:/// See:/// Algorithm:<see...
by Richard MacCutchan
Week numbers according to ISO8601
by Luc Pattyn
This is an alternative to "Week Numbers According to ISO8601".
by Tarie Nosworthy
C and C++ are still very useful indeed.
by dudley52
A C program to walk a drive or folder all the way to the bottom, listing each full file name and length, saving the longest one.
by Kai Schtrom
Display smart messages on the Windows Desktop as XBOX360 achievements
by Steffen Ploetz
Another fully functional ownerdraw menu with minimal effort - this time based on Win32, with icons instead of bitmaps, with accelerators and tested for ReactOS and WinNT 4.0 to Windows 10