ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Anyone knows a good way to make an int out of the escape sequence of an octal value?
Say my QString looks like this: "US\\040of\\40A"
\040 is the octal representation of the <space> character (" ").
I want to code a loop that will replace the "\\040" with " ", or whatever escape sequence it finds with the corresponding character, but for that, I need a way to make an int out of the "\\040" string chunk.
Trust me, I thought of that, but I have no guarantee that my escape sequence will be "\\040", it could be "\\045" or whatever you like, I just don't know.
So instead of writing fragile code, I prefer to just go for the whole nine yards and have a stable thing going on.
I'm a software quality assurance specialist in real life, so my eye is trained to identify potential weaknesses. If my escape string has a default, the rest of the program that's based on it is useless.
Ps: Anyway, I have my code ready, it could replace any octal escape sequence with the corresponding character and I sleep better at night :-)
Sorry I missed the bit about "or whatever escape sequence it finds". Also you've got it working so why fix it?...but I would suggest, if only for future reference that you could us the QString member function toInt().
int dec = test.toInt(&ok,8);
You code will return 40 in decimal, but I want 40 in octal, hence 32 in decimal.
See the trouble I went through now?
With the sscanf code I've written, when I feed the string "040" to sscanf and let it know it's an octal, as in the %o argument, it returns 32 in the variable oct. 32 is the decimal code for <space>, your 40 would be the code for "(".
You were right, all apologies, I was passing the entire escape sequence when trying it yesterday. Your code is much shorter and much more efficient, so even though I've implemented something on my own, I'll still go back and replace it with your solution.