top of page

The "Essential" Standard Functions

  • Writer: Ashok Kumar Kumawat
    Ashok Kumar Kumawat
  • Feb 3
  • 2 min read

In a professional C or embedded environment, we call these Standard Library Functions. While you won't use printf inside a car's braking system (because there is no screen to print to!), you will use it constantly during testing and debugging on your PC or through a UART console.


Close-up view of a microcontroller circuit board
A close-up view of a microcontroller circuit board showcasing its intricate design.

Here is the "Essential List" of functions every embedded engineer should know by heart.

​1. Input / Output Functions (stdio.h)

​printf (Print Formatted)

  • What it does: Sends a formatted string to the "Standard Output" (usually your console).

  • Syntax: int printf(const char *format, ...);

  • Returns: The total number of characters printed. If it fails, it returns a negative number.

​scanf (Scan Formatted)

  • What it does: Reads input from the keyboard/console and stores it in variables.

  • Syntax: int scanf(const char *format, ...);

  • Returns: The number of items successfully read and assigned.

  • Corporate Warning: We rarely use scanf in real products because it is "blocking" (it stops everything until you type) and unsafe if the user types too much data.

​2. String Manipulation (string.h)

​strlen (String Length)

  • What it does: Counts how many characters are in a string (not counting the null terminator \0).

  • Syntax: size_t strlen(const char *str);

  • Returns: The number of characters (as an unsigned integer).

​strcpy (String Copy)

  • What it does: Copies a "Source" string into a "Destination" buffer.

  • Syntax: char strcpy(char dest, const char *src);

  • Returns: A pointer to the destination string.

  • Safety Tip: In the industry, we prefer strncpy because it lets us set a limit so we don't crash the memory (Buffer Overflow).

​strcmp (String Compare)

  • What it does: Compares two strings alphabetically.

  • Syntax: int strcmp(const char str1, const char str2);

  • Returns: * 0 if they are identical.

    • ​Positive if str1 is "greater."

    • ​Negative if str2 is "greater."

​3. Memory Operations (string.h)

Note: These are the "Workhorses" of Embedded C.

​memset (Memory Set)

  • What it does: Fills a block of memory with a specific value.

  • Example: Clearing a sensor data array to all zeros.

  • Syntax: void memset(void ptr, int value, size_t num);

  • Returns: A pointer to the memory area.

​memcpy (Memory Copy)

  • What it does: Copies a block of raw bytes from one place to another.

  • Example: Moving a packet of SPI data into a processing buffer.

  • Syntax: void memcpy(void dest, const void *src, size_t num);

  • Returns: A pointer to the destination.

​4. General Utilities (stdlib.h)

​abs / labs (Absolute Value)

  • What it does: Turns a negative number into a positive one. Very useful for sensor error calculations.

  • Syntax: int abs(int n);

  • Returns: The positive value of the integer.

​atoi (Alpha to Integer)

  • What it does: Converts a string (like "123") into an actual number (123).

  • Syntax: int atoi(const char *str);

  • Returns: The converted integer.


Summary Reference Table

Function

Library

Purpose

Key Return

printf

stdio.h

Output text

Character count

strlen

string.h

Get string size

Length

memset

string.h

Zero-out/Fill memory

Pointer to start

memcpy

string.h

Copy raw data blocks

Pointer to start

strcmp

string.h

Check if strings match

0 if equal


Professor's Challenge:

​In your AUTOSAR/Jacinto testing, you will likely use memcpy to move data from the SPI Internal Buffer to your Test Report buffer.

Recent Posts

See All
Q&A: C Code

Q1: How do you find the size of an array in C? Q2: What is an array of pointers in C, and why is it useful? Q3: How can function pointers be used to trigger callbacks in C? Q4: How can we determine th

 
 
 
Bubble Sort Concept

Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. After each pass, the largest element "bubbles up" to its correct position at the end. C Code Example #i

 
 
 
Storage Classes in Embedded C

Excellent, let’s now systematically cover Storage Classes in Embedded C with the structured breakdown you asked for. 1. Concept Overview Storage classes define scope, lifetime, and visibility of varia

 
 
 

Comments


© 2035 by Robert Caro. Powered and secured by Wix

bottom of page