Basic C Programming Exercises and Code Examples
Task 1: Displaying Patterns
The following program displays a simple character pattern:
#include <stdio.h>
int main() {
printf(" O \n");
printf("<H>\n");
printf("I I\n");
printf(" O \n");
printf("<H>\n");
printf("I I\n");
return 0;
}
Ano ...
Posted on Fri, 26 Jun 2026 17:12:13 +0000 by Huuggee
Resolving Multiple Definition Errors for Global Variables in C
The Problem
When multiple source files include a header that defines global variables, the linker reports multiple definition errors. Consider a header file (main.h) that directly defines global arrays:
#ifndef __MAIN_H
#define __MAIN_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 100
struct studen ...
Posted on Wed, 24 Jun 2026 17:37:45 +0000 by Scooby08
Using RetDec to Decompile a Simple C Program
Consider the following C source file:
#include <stdio.h>
void printff() {
printf("this is called funtion printff");
}
int main(int argc, char *argv[]) {
printff();
printf("This is helo analysis");
if (argc == 2) {
printf("The argument supplied is %s\n", argv[1]);
} else if (argc ...
Posted on Tue, 23 Jun 2026 18:01:09 +0000 by jpt62089
Advanced C Language Pointer Techniques
assert Macro for Debugging
The <assert.h> header file defines the assert() macro, which verifies that a specified condition holds true during program execution. If the condition is false, the program terminates with an error message. This macro is particularly useful for debugging purposes.
Here's how to use it:
assert(data_pointer != ...
Posted on Tue, 23 Jun 2026 17:19:55 +0000 by indian98476
Implementing a Terminal-Based Gomoku Game in C on Linux
Terminal-based board games in C require direct manipulation of standard I/O, raw input processing, and efficient state evaluation. The architecture for a 15x15 Gomoku game on Linux centers on a matrix for piece tracking, POSIX terminal configuration for instant key capture, and directional scanning for win validation.
Board State and Cursor Tra ...
Posted on Tue, 23 Jun 2026 16:41:09 +0000 by angulion
Understanding C Pointer Types and the Const Qualifier
The Significance of Pointer Data Types
In C programming, the type of a pointer does more than just specify what kind of data it points to; it defines the pointer's behavior during memory access and arithmetic operations.
1. Memory Access and Dereferencing
The pointer type determines the "step size" or the number of bytes the CPU acces ...
Posted on Fri, 19 Jun 2026 16:19:41 +0000 by paradigmapc
Command-Line Argument Processing and String Manipulation in C
When processing command-line arguments in C, the main function receives two parameters: argc (argument count) and argv (array of argument strings). The following example demonstrates sorting these arguments lexicographically using qsort with a custom comparator:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int c ...
Posted on Sun, 14 Jun 2026 18:13:32 +0000 by steveangelis
Implementation of DateTime Configuration in NWatch Settings Menu
Initializing the DateTime Configuraton Screen
When entering the DateTime settings screen, the interface is initialized with appropriate menu options and callbacks. This screen uses string-based (STR) rendering.
static void updateTimeDisplay(void) {
char buffer[17];
uint8_t displayMode = (timeDateSet.time.ampm != CHAR_24) ? 12 : 24;
...
Posted on Thu, 11 Jun 2026 18:29:00 +0000 by John_S
Understanding and Using the Java native Keyword
The native modifier in Java marks a method whose implementation is supplied by code written in another language—usually C or C++. A typical example is Object.hashCode():
public native int hashCode();
Because the JVM cannot directly manipulate raw memory or hardware, such low-level work is delegated to platform-specific native libraries. The Ja ...
Posted on Wed, 03 Jun 2026 18:14:57 +0000 by _OwNeD.YoU_
Approaching Redis Source Code: A Practical Guide
Overview of Redis
Redis (Remote Dictionary Server) is an open-source, high-performance key-value store written in C by Salvatore Sanfilippo. Licensed under the BSD license, it stands out from other caching systems like Memcached due to several core features:
Persistence: Supports saving in-memory data to disk for recovery after restarts.
Ri ...
Posted on Tue, 02 Jun 2026 17:25:32 +0000 by phpgeek17