Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Ultimate C Programming Reference Programming
Download Open
Show description 2,401 chars · Programming

Ultimate C Programming Reference

Ultimate C Programming Reference





⚡ ULTIMATE C PROGRAMMING REFERENCE ⚡

Your complete guide to C programming mastery





Functions
Memory
Strings
Math
Files
Glossary




🔥 BASIC I/O FUNCTIONS




Function

Description

Example





printf()
print formatted output to screen
printf("hello %s\n", name);


scanf()
read formatted input from user
scanf("%d", &number);


getchar()
read single character
char c = getchar();


putchar()
print single character
putchar('A');


puts()
print string with newline
puts("hello world");


fgets()
safe string input
fgets(buffer, 100, stdin);








💾 MEMORY MANAGEMENT




Function

Description

Example





malloc()
allocate memory on heap
int *ptr = malloc(10 * sizeof(int));


calloc()
allocate zeroed memory
int *ptr = calloc(10, sizeof(int));


realloc()
resize allocated memory
ptr = realloc(ptr, 20 * sizeof(int));


free()
deallocate memory
free(ptr);


sizeof()
get size of data type
int size = sizeof(int);








📝 STRING FUNCTIONS

Requires: #include <string.h>




Function

Description

Example





strlen()
get string length
int len = strlen("hello");


strcpy()
copy string
strcpy(dest, source);


strncpy()
copy n characters
strncpy(dest, source, 5);


strcat()
concatenate strings
strcat(dest, source);


strcmp()
compare strings
if (strcmp(str1, str2) == 0)


strchr()
find character in string
char *pos = strchr(str, 'a');


strstr()
find substring
char *pos = strstr(str, "hello");








🧮 MATH FUNCTIONS

Requires: #include <math.h>




Function

Description

Example





pow()
power function
double result = pow(2.0, 3.0);


sqrt()
square root
double result = sqrt(16.0);


abs()
absolute value (int)
int result = abs(-5);


fabs()
absolute value (double)
double result = fabs(-5.5);


ceil()
round up
double result = ceil(4.2);


floor()
round down
double result = floor(4.8);


rand()
random number
int num = rand() % 100;


srand()
seed random generator
srand(time(NULL));








📁 FILE OPERATIONS




Function

Description

Example





fopen()
open file
FILE *fp = fopen("file.txt", "r");


fclose()
close file
fclose(fp);


fread()
read from file
fread(buffer, 1, 100, fp);


fwrite()
write to file
fwrite(data, 1, 100, fp);


fprintf()
print to file
fprintf(fp, "number: %d\n", num);


fscanf()
re…

Ultimate C Programming Reference

23,172 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ultimate C Programming Reference</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            background: linear-gradient(135deg, #0c0c0c, #1a0000);
            color: #e0e0e0;
            line-height: 1.6;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            padding: 40px 0;
            background: linear-gradient(45deg, #330000, #660000, #330000);
            margin-bottom: 40px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(255, 0, 0, 0.3);
            border: 2px solid #ff3333;
        }

        .header h1 {
            font-size: 3em;
            color: #ff4444;
            text-shadow: 0 0 20px #ff0000;
            margin-bottom: 10px;
            font-weight: bold;
        }

        .header p {
            font-size: 1.2em;
            color: #ffaaaa;
            text-shadow: 0 0 10px #ff0000;
        }

        .navigation {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 15px;
            margin-bottom: 40px;
            padding: 20px;
            background: rgba(51, 0, 0, 0.3);
            border-radius: 10px;
            border: 1px solid #ff3333;
        }

        .nav-link {
            padding: 10px 20px;
            background: linear-gradient(45deg, #ff3333, #cc0000);
            color: white;
            text-decoration: none;
            border-radius: 25px;
            transition: all 0.3s ease;
            border: 2px solid transparent;
            font-weight: bold;
        }

        .nav-link:hover {
            background: linear-gradient(45deg, #ff6666, #ff3333);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(255, 51, 51, 0.4);
            border-color: #ffaaaa;
        }

        .section {
            margin-bottom: 50px;
            padding: 30px;
            background: linear-gradient(135deg, #1a1a1a, #0d0d0d);
            border-radius: 15px;
            border: 2px solid #ff3333;
            box-shadow: 0 5px 20px rgba(255, 0, 0, 0.2);
        }

        .section h2 {
            color: #ff4444;
            font-size: 2.2em;
            margin-bottom: 25px;
            text-align: center;
            text-shadow: 0 0 15px #ff0000;
            border-bottom: 3px solid #ff3333;
            padding-bottom: 15px;
        }

        .section h3 {
            color: #ff6666;
            font-size: 1.5em;
            margin: 25px 0 15px 0;
            text-shadow: 0 0 10px #ff0000;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 30px;
            background: rgba(26, 26, 26, 0.8);
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(255, 0, 0, 0.2);
        }

        th {
            background: linear-gradient(45deg, #ff3333, #cc0000);
            color: white;
            padding: 15px;
            text-align: left;
            font-weight: bold;
            text-shadow: 0 0 5px #000;
        }

        td {
            padding: 12px 15px;
            border-bottom: 1px solid #ff3333;
            vertical-align: top;
        }

        tr:nth-child(even) {
            background: rgba(51, 0, 0, 0.1);
        }

        tr:hover {
            background: rgba(255, 51, 51, 0.1);
            transform: scale(1.01);
            transition: all 0.2s ease;
        }

        code {
            background: linear-gradient(45deg, #330000, #1a0000);
            color: #ffaaaa;
            padding: 3px 8px;
            border-radius: 5px;
            font-family: 'Consolas', 'Monaco', monospace;
            border: 1px solid #ff3333;
            box-shadow: 0 2px 5px rgba(255, 0, 0, 0.2);
        }

        .glossary-item {
            margin-bottom: 25px;
            padding: 20px;
            background: linear-gradient(135deg, #262626, #1a1a1a);
            border-radius: 10px;
            border-left: 5px solid #ff3333;
            box-shadow: 0 3px 10px rgba(255, 0, 0, 0.1);
            transition: all 0.3s ease;
        }

        .glossary-item:hover {
            transform: translateX(10px);
            box-shadow: 0 5px 20px rgba(255, 51, 51, 0.3);
        }

        .glossary-term {
            color: #ff4444;
            font-size: 1.3em;
            font-weight: bold;
            margin-bottom: 10px;
            text-shadow: 0 0 8px #ff0000;
        }

        .glossary-description {
            color: #e0e0e0;
            margin-bottom: 10px;
            line-height: 1.7;
        }

        .glossary-code {
            background: linear-gradient(45deg, #0d0d0d, #1a0000);
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #ff3333;
            font-family: 'Consolas', monospace;
            color: #ffcccc;
            overflow-x: auto;
        }

        .scroll-top {
            position: fixed;
            bottom: 30px;
            right: 30px;
            background: linear-gradient(45deg, #ff3333, #cc0000);
            color: white;
            padding: 15px;
            border-radius: 50%;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid #ff6666;
            box-shadow: 0 5px 15px rgba(255, 51, 51, 0.4);
        }

        .scroll-top:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(255, 51, 51, 0.6);
        }

        @media (max-width: 768px) {
            .header h1 {
                font-size: 2em;
            }
            
            .navigation {
                flex-direction: column;
                align-items: center;
            }
            
            table {
                font-size: 0.9em;
            }
            
            .section {
                padding: 20px;
            }
        }

        /* Scrollbar styling */
        ::-webkit-scrollbar {
            width: 12px;
        }

        ::-webkit-scrollbar-track {
            background: #1a1a1a;
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb {
            background: linear-gradient(45deg, #ff3333, #cc0000);
            border-radius: 10px;
            border: 2px solid #1a1a1a;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(45deg, #ff6666, #ff3333);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>⚡ ULTIMATE C PROGRAMMING REFERENCE ⚡</h1>
            <p>Your complete guide to C programming mastery</p>
        </div>

        <div class="navigation">
            <a href="#functions" class="nav-link">Functions</a>
            <a href="#memory" class="nav-link">Memory</a>
            <a href="#strings" class="nav-link">Strings</a>
            <a href="#math" class="nav-link">Math</a>
            <a href="#files" class="nav-link">Files</a>
            <a href="#glossary" class="nav-link">Glossary</a>
        </div>

        <section id="functions" class="section">
            <h2>🔥 BASIC I/O FUNCTIONS</h2>
            <table>
                <thead>
                    <tr>
                        <th>Function</th>
                        <th>Description</th>
                        <th>Example</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td><code>printf()</code></td><td>print formatted output to screen</td><td><code>printf("hello %s\n", name);</code></td></tr>
                    <tr><td><code>scanf()</code></td><td>read formatted input from user</td><td><code>scanf("%d", &number);</code></td></tr>
                    <tr><td><code>getchar()</code></td><td>read single character</td><td><code>char c = getchar();</code></td></tr>
                    <tr><td><code>putchar()</code></td><td>print single character</td><td><code>putchar('A');</code></td></tr>
                    <tr><td><code>puts()</code></td><td>print string with newline</td><td><code>puts("hello world");</code></td></tr>
                    <tr><td><code>fgets()</code></td><td>safe string input</td><td><code>fgets(buffer, 100, stdin);</code></td></tr>
                </tbody>
            </table>
        </section>

        <section id="memory" class="section">
            <h2>💾 MEMORY MANAGEMENT</h2>
            <table>
                <thead>
                    <tr>
                        <th>Function</th>
                        <th>Description</th>
                        <th>Example</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td><code>malloc()</code></td><td>allocate memory on heap</td><td><code>int *ptr = malloc(10 * sizeof(int));</code></td></tr>
                    <tr><td><code>calloc()</code></td><td>allocate zeroed memory</td><td><code>int *ptr = calloc(10, sizeof(int));</code></td></tr>
                    <tr><td><code>realloc()</code></td><td>resize allocated memory</td><td><code>ptr = realloc(ptr, 20 * sizeof(int));</code></td></tr>
                    <tr><td><code>free()</code></td><td>deallocate memory</td><td><code>free(ptr);</code></td></tr>
                    <tr><td><code>sizeof()</code></td><td>get size of data type</td><td><code>int size = sizeof(int);</code></td></tr>
                </tbody>
            </table>
        </section>

        <section id="strings" class="section">
            <h2>📝 STRING FUNCTIONS</h2>
            <p style="color: #ffaaaa; margin-bottom: 20px;">Requires: <code>#include &lt;string.h&gt;</code></p>
            <table>
                <thead>
                    <tr>
                        <th>Function</th>
                        <th>Description</th>
                        <th>Example</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td><code>strlen()</code></td><td>get string length</td><td><code>int len = strlen("hello");</code></td></tr>
                    <tr><td><code>strcpy()</code></td><td>copy string</td><td><code>strcpy(dest, source);</code></td></tr>
                    <tr><td><code>strncpy()</code></td><td>copy n characters</td><td><code>strncpy(dest, source, 5);</code></td></tr>
                    <tr><td><code>strcat()</code></td><td>concatenate strings</td><td><code>strcat(dest, source);</code></td></tr>
                    <tr><td><code>strcmp()</code></td><td>compare strings</td><td><code>if (strcmp(str1, str2) == 0)</code></td></tr>
                    <tr><td><code>strchr()</code></td><td>find character in string</td><td><code>char *pos = strchr(str, 'a');</code></td></tr>
                    <tr><td><code>strstr()</code></td><td>find substring</td><td><code>char *pos = strstr(str, "hello");</code></td></tr>
                </tbody>
            </table>
        </section>

        <section id="math" class="section">
            <h2>🧮 MATH FUNCTIONS</h2>
            <p style="color: #ffaaaa; margin-bottom: 20px;">Requires: <code>#include &lt;math.h&gt;</code></p>
            <table>
                <thead>
                    <tr>
                        <th>Function</th>
                        <th>Description</th>
                        <th>Example</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td><code>pow()</code></td><td>power function</td><td><code>double result = pow(2.0, 3.0);</code></td></tr>
                    <tr><td><code>sqrt()</code></td><td>square root</td><td><code>double result = sqrt(16.0);</code></td></tr>
                    <tr><td><code>abs()</code></td><td>absolute value (int)</td><td><code>int result = abs(-5);</code></td></tr>
                    <tr><td><code>fabs()</code></td><td>absolute value (double)</td><td><code>double result = fabs(-5.5);</code></td></tr>
                    <tr><td><code>ceil()</code></td><td>round up</td><td><code>double result = ceil(4.2);</code></td></tr>
                    <tr><td><code>floor()</code></td><td>round down</td><td><code>double result = floor(4.8);</code></td></tr>
                    <tr><td><code>rand()</code></td><td>random number</td><td><code>int num = rand() % 100;</code></td></tr>
                    <tr><td><code>srand()</code></td><td>seed random generator</td><td><code>srand(time(NULL));</code></td></tr>
                </tbody>
            </table>
        </section>

        <section id="files" class="section">
            <h2>📁 FILE OPERATIONS</h2>
            <table>
                <thead>
                    <tr>
                        <th>Function</th>
                        <th>Description</th>
                        <th>Example</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td><code>fopen()</code></td><td>open file</td><td><code>FILE *fp = fopen("file.txt", "r");</code></td></tr>
                    <tr><td><code>fclose()</code></td><td>close file</td><td><code>fclose(fp);</code></td></tr>
                    <tr><td><code>fread()</code></td><td>read from file</td><td><code>fread(buffer, 1, 100, fp);</code></td></tr>
                    <tr><td><code>fwrite()</code></td><td>write to file</td><td><code>fwrite(data, 1, 100, fp);</code></td></tr>
                    <tr><td><code>fprintf()</code></td><td>print to file</td><td><code>fprintf(fp, "number: %d\n", num);</code></td></tr>
                    <tr><td><code>fscanf()</code></td><td>read formatted from file</td><td><code>fscanf(fp, "%d", &num);</code></td></tr>
                    <tr><td><code>feof()</code></td><td>check end of file</td><td><code>while (!feof(fp))</code></td></tr>
                </tbody>
            </table>
        </section>

        <section id="glossary" class="section">
            <h2>📚 PROGRAMMING GLOSSARY</h2>
            
            <h3>Data Structures & Memory</h3>
            
            <div class="glossary-item">
                <div class="glossary-term">array</div>
                <div class="glossary-description">Collection of elements of same type stored in contiguous memory</div>
                <div class="glossary-code">int numbers[5] = {1, 2, 3, 4, 5}; // array of 5 integers</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">struct</div>
                <div class="glossary-description">Custom data type that groups related variables together</div>
                <div class="glossary-code">struct student {<br>&nbsp;&nbsp;&nbsp;&nbsp;char name[50];<br>&nbsp;&nbsp;&nbsp;&nbsp;int age;<br>&nbsp;&nbsp;&nbsp;&nbsp;float gpa;<br>};</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">heap</div>
                <div class="glossary-description">Dynamic memory area where malloc/calloc allocate memory. You control when to free it</div>
                <div class="glossary-code">int *ptr = malloc(100 * sizeof(int)); // allocated on heap</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">stack</div>
                <div class="glossary-description">Automatic memory area where local variables live. Automatically cleaned up when function ends</div>
                <div class="glossary-code">void func() {<br>&nbsp;&nbsp;&nbsp;&nbsp;int x = 10; // x lives on the stack<br>}</div>
            </div>

            <h3>Pointers & Memory Operations</h3>

            <div class="glossary-item">
                <div class="glossary-term">pointer</div>
                <div class="glossary-description">Variable that stores the memory address of another variable</div>
                <div class="glossary-code">int x = 42;<br>int *ptr = &x; // ptr is a pointer, stores address of x</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">dereference pointer</div>
                <div class="glossary-description">Using * to access the value that a pointer points to</div>
                <div class="glossary-code">int value = *ptr; // dereference ptr to get the value</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">& operator</div>
                <div class="glossary-description">"Address of" operator, gets the memory address of a variable</div>
                <div class="glossary-code">int x = 10;<br>int *ptr = &x; // get address of x</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">-> operator</div>
                <div class="glossary-description">Shorthand for accessing struct members through a pointer</div>
                <div class="glossary-code">struct point *p = malloc(sizeof(struct point));<br>p->x = 10;     // same as (*p).x = 10;</div>
            </div>

            <h3>Data Types & Declarations</h3>

            <div class="glossary-item">
                <div class="glossary-term">union</div>
                <div class="glossary-description">Like struct but all members share the same memory location</div>
                <div class="glossary-code">union data {<br>&nbsp;&nbsp;&nbsp;&nbsp;int i;<br>&nbsp;&nbsp;&nbsp;&nbsp;float f;<br>&nbsp;&nbsp;&nbsp;&nbsp;char c;<br>}; // only one member can hold a value at a time</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">enumeration (enum)</div>
                <div class="glossary-description">Defines a set of named integer constants</div>
                <div class="glossary-code">enum day {MONDAY, TUESDAY, WEDNESDAY}; // MONDAY=0, TUESDAY=1, etc.</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">unsigned</div>
                <div class="glossary-description">Data type modifier that only allows positive numbers (no negative)</div>
                <div class="glossary-code">unsigned int count = 42; // can't be negative, larger positive range</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">type alias (typedef)</div>
                <div class="glossary-description">Creates a new name for an existing data type</div>
                <div class="glossary-code">typedef struct point Point;     // now can use Point instead of struct point<br>typedef int* IntPtr;            // IntPtr is now alias for int*</div>
            </div>

            <h3>Compilation & Preprocessing</h3>

            <div class="glossary-item">
                <div class="glossary-term">compiler</div>
                <div class="glossary-description">Program that translates your C code into machine code that the CPU can execute</div>
                <div class="glossary-code">// gcc -o program program.c  // gcc is the compiler</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">macro</div>
                <div class="glossary-description">Preprocessor directive that defines text replacement</div>
                <div class="glossary-code">#define SQUARE(x) ((x) * (x))<br>int result = SQUARE(5); // becomes ((5) * (5))</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">recursion</div>
                <div class="glossary-description">When a function calls itself to solve smaller versions of the same problem</div>
                <div class="glossary-code">int factorial(int n) {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (n <= 1) return 1;           // base case<br>&nbsp;&nbsp;&nbsp;&nbsp;return n * factorial(n - 1);    // recursive case<br>}</div>
            </div>

            <h3>Memory Issues & Debugging</h3>

            <div class="glossary-item">
                <div class="glossary-term">memory leak</div>
                <div class="glossary-description">When you malloc memory but forget to free it</div>
                <div class="glossary-code">void bad_function() {<br>&nbsp;&nbsp;&nbsp;&nbsp;int *ptr = malloc(100 * sizeof(int));<br>&nbsp;&nbsp;&nbsp;&nbsp;// forgot free(ptr); - this is a memory leak<br>}</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">segmentation fault (segfault)</div>
                <div class="glossary-description">Trying to access memory you're not allowed to</div>
                <div class="glossary-code">int *ptr = NULL;<br>*ptr = 10; // segfault - dereferencing null pointer</div>
            </div>

            <div class="glossary-item">
                <div class="glossary-term">buffer overflow</div>
                <div class="glossary-description">Writing past the end of an array</div>
                <div class="glossary-code">char buffer[5];<br>strcpy(buffer, "this string is too long"); // buffer overflow</div>
            </div>
        </section>
    </div>

    <div class="scroll-top" onclick="scrollToTop()">↑</div>

    <script>
        function scrollToTop() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        }

        // Smooth scrolling for navigation links
        document.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', function(e) {
                e.preventDefault();
                const targetId = this.getAttribute('href').substring(1);
                const targetElement = document.getElementById(targetId);
                if (targetElement) {
                    targetElement.scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });
                }
            });
        });

        // Show/hide scroll to top button
        window.addEventListener('scroll', function() {
            const scrollButton = document.querySelector('.scroll-top');
            if (window.pageYOffset > 300) {
                scrollButton.style.display = 'block';
            } else {
                scrollButton.style.display = 'none';
            }
        });
    </script>
</body>
</html>