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 7577045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:05:08+00:00 2026-05-30T17:05:08+00:00

I want to supply escape characters for my C program as command line arguments:

  • 0

I want to supply escape characters for my C program as command line arguments:

#include <cstring>
#include <cstdio>
int main(int argc,char**argv){
  const char *str1 = "\t";
  const char *str2 = argv[1];
  fprintf(stderr,"str1:%s:\nstr2:%s:\n",str1,str2);
  return 0;
}

When running this it gives:

/a.out "\t"
str1:   :
str2:\t:

So it looks like my \t is being interpreted as slash t instead of tab

Is there an easy solution for this, or do I have to check for every escape charechter I want my program to handle? Something like this?:

char *truetab="\t";
if(argv[1][0]=='\\' && argv[1][1]=='t')
   res = truetab;

Thanks.

  • 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-05-30T17:05:10+00:00Added an answer on May 30, 2026 at 5:05 pm

    Unfortunately, you need to do it manually: processing escape sequences is compiler’s job, by the time the "hello\tworld" constant ends up in the area of string constants in the compiled code, the \t is already replaced by the ASCII code 9 (TAB). It should not be that difficult – in fact, it’s an exercise number 3.2 of the classic K&R book:

    Exercise 3-2. Write a function escape(s,t) that converts characters like newline and tab into
    visible escape sequences like \n and \t as it copies the string t to s. Use a switch. Write a
    function for the other direction as well, converting escape sequences into the real characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to supply the shared libraries along with my program rather than using
I want to pass the string !changeme! to a java program on the command
Our Client requires that we supply Widgits for their site. They want to link
I want to supply a SQL statement from the query string, but all my
I want to supply an output parameter to my stored proc. This output proc
I am building a pretty complex predicate in several iterations, and want to supply
In case of Default or Empty I want to supply some value: string[] str
I have a function with the name MakeInitialCapital. I want to supply control name
SUMMARY: I have created a SSRS Report. I want to be able to supply
I'm using the hash_map in C++ and want to supply a simplified type name

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.