How can I get an int next to a word using scanf? - scanf

How can I extract an int contained in a string like att249 or berlin32 using sscanf ?
I tried
"%s%d"
Which doesn't work because the %s scan doesn't stop on the 2

After asking on the OCaml discord, I got the answer on how to achieve this :
"%[^0-9]%d"
Which works well because %[^0-9] scan until it encounters a digit.
Being a complete beginner in scanf, I don't know if it's the best way to achieve it though.

Related

Autohotkey / AHK - String as function parameter without " "

Is there any way to define function parameter as string by default, so I could send them without using double quotes?
If you know C++ and want to compile your own version of AHK from the source code, or if you want to make an other script which will insert in the quotes automatically after the fact, then yes. Otherwise no.
And I really don't know why you'd want to do this. Seems terrible in my opinion.
Maybe you're used to legacy AHK? If so, you really should let go of that. Maybe about 10 years ago it was fine to use.

Check if word is part of contextfree language

Good evening to all!
As a fan of regular expressions in Perl, I came up with a question, which I could not answer by googling and searching for myself.
So let me give you a minimal example of my problem:
I have two text-files:
FileA.txt:
aaabbb
FileB.txt:
abbb
I want to check each file-content if it is a word, generated by a specific contextfree language. For example in this case:
L={a^nb^n | n > 0}.
Now I have the problem, that the regex from Perl won't work, since it isn't a regular language.
For sure I could script a little PDA and check if it terminates.
But is there another way in Perl to solve this problem? Maybe a way to pass a context-free-grammar or sth.?

Io language user input

I recently started messing around with the Io programming language and think it's pretty fun and simple to learn. But I also hate that there is so little documentation and support for it. Normally I come to SO for help, but even on here the topic is sparse.
I am learning from the 7 languages in 7 weeks book, which I like, but there he mainly talks about the deeper uses of Io.
My question is probably extremely simple but I can't find an answer anywhere... How do you actually ask a user for input? I've found ways to pass along set strings, read in strings from files, but I can't find a way to ask a user for input.
What I'm working on now is writing a function that accepts 2 parameters: a string and a substring to find in that string. The function finds the substring in the string and prints the index. I don't even know if I should be asking the user for input or doing this another way...
I'm trying to get some keyboard time in on Io but it's frustrating :/
Also, does anyone know of any IRC channels that are friendly to beginners? Not necessarily just Io, but in general?
Thanks guys.
On the topic of IRC, there's irc.freenode.net and the #io channel. We're not always active, but if you hang around, I usually poke in at least once a day.
On the topic of user input however, You can do this:
x := File standardInput readLine
This will get a single line of input, up to where the user hit the enter/return key, and capture that in x.

Using text as condition in a while loop

Im having some trouble with using text as an condition for a while loop, currently the basic coding is:
result=struct('val','yes');
while result.val=='yes'
result.val=input('more digits?');
end
So as you see, what Im trying to do is keeping the loop going as long as the user types in 'yes'. But thats one of the probelmes I am having; Is there a way to get rid of the need to write the ''(e.g yes instead of 'yes')? Secondly, when I run the code it gives me the error message "Error using == ,Matrix dimensions must agree.". I realise this have to do with the word yes being longer than no, but I don't know how to fix it. It's not really an issue though considering its the the program ends anyway, but it is an annoyance I would like to get rid off.
To compare strings, use strcmp, or strcmpi to ignore case. It will handle comparison of different length strings. For example:
strcmpi(result.val,'yes')
If you want to search for a substring, such as just a 'y', at the beginning of the input, consider strncmpi (strncmpi(result.val,'y',1)) or just check the first character (result.val(1)).

How to find literals in source code of Smartforms and in SAPScripts (or reports, if the others can't be done)

I'd like to check hardcoded values in (a lot of) Smartforms and SAPScript forms.
I have found a way to read the source code of both of these, but it seems that i will have to go through a lot of parsing before I get anything reliable.
I've come across function module GET_LITERAL but that doesn't seem to help me much since i have to specify the offset of the value, if i got right what the function is doing in the first place.
I also found RS_LITERAL_LIST but that also doesn't do what i expect.
I also tried searching for reports and methods, but haven't found anything that seemed to help.
A backup plan would be to get some good parsing tool, so do you know of anything like that.
Anyway, any hints would be helpful and appreciated.
[EDIT]
Forgot to mention, the version of my system is 4.6C
If you have a fairly recent version of ABAP, you can use a regex.
Follow the pattern of this example, but use your source as the text and create your own regex. Have it look for any single quotes on the end of a word separated by spaces or any integers with spaces on either side. That's just a start, you might need to work on a better pattern.
String functions count, find, and match