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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:12:09+00:00 2026-06-14T13:12:09+00:00

just to give you background. We have a school project where we need to

  • 0

just to give you background. We have a school project where we need to write our own compiler in C. My task is to write a lexical analysis. So far so good but I am having some difficulties with escape sequences.

When I find an escape sequence and the escape sequence is correct I have it saved in a string which looks like this \xAF otherwise it is lexical error.

My problem is how do I convert the string containing only escape sequence to one char? So I can add it to “buffer” containing the rest of the string.

I had an idea about a massive table containing only escape sequences and then comparing it one by one but it does not seem elegant.

  • 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-14T13:12:10+00:00Added an answer on June 14, 2026 at 1:12 pm

    you can use the following code, call xString2char with your string.

    char x2char(const char c)
    {
        if (c >= '0' && c <= '9')
            return c - '0';
        if (c >= 'a' && c <= 'f')
            return c - 'a';
        if (c >= 'A' && c <= 'F')
            return c - 'A';
        //if we got here it's an error - handle it as you like...
    }
    
    char xString2char(const char* buf)
    {
        char ans;
        ans = x2char(buf[2]);
        ans <<= 4;
        ans += x2char(buf[3]);
        return ans;
    }
    

    This should work, just add the error checking & handling (in case you didn’t already validate them in your code)

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

Sidebar

Related Questions

My code isn't really that relevant but just to give you background, I have
Just to give a little background: I'm using Dreamweaver CS5 for coding php, XAMPP
I have written a Perl script, I just want to give it to every
The compiler doesn't give me any error and the code runs. Just curious how
I have a background task that updates a view. That task calls -setNeedsDisplay to
The following two paragraphs are background - they just explain why I need to
So I have a background procss that I need to expose/control as a web
The Issue Just to give you some background, I'm currently enrolled as a student
I need to write a common class for handling http request in the background
I do not know how to ask this question. So I will just give

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.