Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:52+00:00 2026-06-13T12:21:52+00:00

I need to check if my program is correctly inputting these characters in my

  • 0

I need to check if my program is correctly inputting these characters in my strings, so how can I see a “raw” string with these characters not parsed but actually shown?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:21:53+00:00Added an answer on June 13, 2026 at 12:21 pm

    If you read input (from file or from user) the special escape codes are not parsed. It’s only in string and character literals in the source that the compiler treats those specially.

    Edit: Simple example program with input and output to show what I’m talking about.

    #include <stdio.h>
    #include <string.h>
    
    int main(int ac, char *av[])
    {
        char input[32];
    
        printf("Enter input: ");
        fgets(input, sizeof(input), stdin);
    
        /* Remove trailing newline */
        if (input[strlen(input) - 1] == '\n')
            input[strlen(input) - 1] = '\0';
    
        printf("input is \"%s\"\n", input);
    
        return 0;
    }
    

    Example run of the above program:

    Enter input: foo\nbar\thello
    input is "foo\nbar\thello"
    

    The function fgets leaves the actual newline at the end of the string. However, the sequences \n and \t in the input does not get translated to newline or tab (respectively). That is because it’s not the input or output functions that handles these special character sequences, but the compiler.

    If you have those sequences inside a string or character literal in the source, then the compiler recognizes those and changes them to a proper newline, tab or whatever it is you wrote. However, as the compiler doesn’t know anything about input read from a file or from a user, these sequences are not translated.

    Edit 2: In case you wonder about how to show literal special characters in a string, then please see this program:

    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    void print_raw_string(const char *str)
    {
        while (*str != '\0')
        {
            if (isprint(*str))
                fputc(*str, stdout);
            else
            {
                switch (*str)
                {
                    /* First check for known special sequences */
                case '\0':
                    printf("\\0");
                    break;
                case '\a':
                    printf("\\a");
                    break;
                case '\b':
                    printf("\\b");
                    break;
                case '\t':
                    printf("\\t");
                    break;
                case '\n':
                    printf("\\n");
                    break;
                case '\v':
                    printf("\\v");
                    break;
                case '\f':
                    printf("\\f");
                    break;
                case '\r':
                    printf("\\r");
                    break;
    
                default:
                    /* None of the above, print it out as a hex escape sequence */
                    printf("\\x%02x", *str);
                    break;
                }
            }
    
            str++;
        }
    }
    
    int main(int ac, char *av[])
    {
        char input[32];
    
        printf("Enter input: ");
        fgets(input, sizeof(input), stdin);
    
        printf("Input is: ");
        print_raw_string(input);
        printf("\n");
    
        return 0;
    }
    

    When running the program:

    Enter input: foo    bar
    Input is: foo\tbar\n
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a monitoring/watchdog program to check a series of application The
Since I write a command line program to check cpp files, and it need
I'm writing a 'Sudoku' program, and I need to write a method to check
I need to check if a link (a-tag) is the only content (not just
I need to check to see if a directory is empty. The problem is,
I am writing a fairly simple journal entry program, and I need to check
How can I check programmatically, how much memory my program currently has allocated ?
I need to check for the location of a file during program installation utilizing
I need a program that checks if the difference between all pairs of elements
We are running an erlang program (ejabberd). Sometimes, we need to do health checks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.