Convert integer into string (manual logic) Dry Run in C

Convert integer into string (manual logic) is an interactive C dry run visualizer from the String Functions programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Convert integer into string (manual logic) Program Code

#include <stdio.h>

void intToString(int num, char str[]) {
    int i = 0;
    int isNegative = 0;
    
    // Handle 0 separately
    if(num == 0) {
        str[i++] = '0';
        str[i] = '\0';
        return;
    }
    
    // Handle negative numbers
    if(num < 0) {
        isNegative = 1;
        num = -num;
    }
    
    // Extract digits in reverse order
    char temp[100];
    int j = 0;
    while(num > 0) {
        temp[j++] = (num % 10) + '0';
        num = num / 10;
    }
    
    // Add negative sign if needed
    if(isNegative) {
        str[i++] = '-';
    }
    
    // Reverse digits to correct order
    for(k = j - 1; k >= 0; k--) {
        str[i++] = temp[k];
    }
    str[i] = '\0';
}

int main() {
    int num1 = 12345;
    int num2 = -6789;
    int num3 = 0;
    char result[100];
    
    intToString(num1, result);
    printf("%d as string: '%s'\n", num1, result);
    
    intToString(num2, result);
    printf("%d as string: '%s'\n", num2, result);
    
    intToString(num3, result);
    printf("%d as string: '%s'\n", num3, result);
    
    return 0;
}

View the complete String Functions programs page.

Program Console Convert integer into string (manual logic) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.