Remove Newline Character from Input String Dry Run in C

Remove Newline Character from Input String is an interactive C dry run visualizer from the Strings 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.

Remove Newline Character from Input String Program Code

#include <stdio.h>
#include <string.h>
int main() {
    char str[100];
    
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    
    // Remove newline if present
    int len = strlen(str);
    if(len > 0 && str[len-1] == '\n') {
        str[len-1] = '\0';
    }
    
    printf("Cleaned string: \"%s\"\n", str);
    printf("Length after cleanup: %d\n", strlen(str));
    
    return 0;
}

View the complete Strings programs page.

Program Console Remove Newline Character from Input String Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.