Convert string to decimal ascii (dec) representation in AHK - loops

I've been struggling to get this to work for a little while and debugging it has been a pain... I'm running into a few different issues.
I prompt for user input something like this:
InputBox, stuff, Enter information, Enter obfuscated information in the box below,,,,,,,30000,
dexStuff= ""
Loop, Parse, stuff
dexStuff:= AscToDec(%A_LoopField%)
The AscToDec function is painfully simple:
AscToDec(c){
return Asc(c)
}
This is ending up with dexStuff as 0000 when I enter "test" as my string. If I change the call of AscToDec() to just MsgBox %A_LoopField% it prints out t e s t in different popups.
Can someone help me understand what I'm doing wrong here?

To concatenate the converted characters of your input, use this:
InputBox, stuff, Enter information, Enter obfuscated information in the box below,,,,,,,30000,
Loop, Parse, stuff
dexStuff := dexStuff . Asc(A_LoopField)
MsgBox %dexStuff%

I see two bugs in your code. First, initializing dexStuff isn't necessary, but if you do so, use either dexStuff= or dexStuff:="", not dexStuff="" which sets dexStuff to two quotation marks. Second, you don't need to dereference A_LoopField in your function call by using percent signs.
Here is your corrected code
InputBox, stuff, Enter information, Enter obfuscated information in the box below,,,,,,,30000,
dexStuff:="" ; := operator, not =
Loop, Parse, stuff
dexStuff:= AscToDec(A_LoopField) ; A_LoopField not %A_LoopField%

Related

how to print with a while also using a scanf statement

I have an odd situation ive made a login system that has many printf and color statements
______________________________________________________________
example border_red(); printf (" $$ ");
_____________________________________________________________
I have multiple printf statements in the menu and in the middle of my code I have a scanf statment to scan the username. The menu gets cut off halfway through making just the top part of the menu appear.
WHAT THE MENU IS SUPPOST TO LOOK LIKE
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ username:type here $
$ $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
WHAT THE MENU LOOKS LIKE
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ username: type here
i need the entire menu to show when you type in your username
QUESTION: How would i go about printing letters after a scanf statement
char username[50];
printf("#############################");
pritnf("# username:");
scanf(log, & username);
printf(# #');
printf("#############################");
how would i go about not having the scanf statement cut off my menu
Sorry if this is a simple question I may have googled it wrong but ive been at this for 1 hour now and this is the only thing I can turn to.
Both scanf and printf assume line-oriented input and output (think of a hardcopy terminal or teletype). They're just not designed to print a border, then scan from a location within that border1.
If you want to set up borders or place input fields in arbitrary places on screen, you'll have to look beyond the standard C library and use a third-party tool like ncurses.
There are tricks you can use - you can send ANSI terminal escape sequences to place the cursor at arbitrary locations on the screen, but it's ugly and a lot of work. You're better off using a library like ncurses.

Can system() echo the data from an input file to CMD?

I'm trying to save useless printf() functions, and echo the data that's in my input file (.txt) whenever I start the program, I'm trying to do it with a system() function that uses command redirections.
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true
The data that I'm trying to echo is the intro and a set of rules:
A secret password was chosen to protect the credit card of Pancratius,
the descendant of Antiochus.
Your mission is to stop Pancratius by revealing his secret password.
The rules are as follows:
1. In each round you try to guess the secret password (4 distinct digits)
2. After every guess you'll receive two hints about the password HITS: The number of digits in your guess which were exactly right.
MISSES: The number of digits in your guess which belongs to
the password but were miss-placed.
Is it possible to do so?
if so, which redirect command should I use?
can it be something like
system("program.exe < input.txt")
?
Thanks.
EDIT:
I really want to avoid using a single printf() and the whole text in it and using "\n" etc. or using lots of printf() functions (as stated above) for each sentence etc.
First of all, using system() instead of printf() just for avoiding printf() is a bad idea. If you really want to read from file, read this.
If this is why you don't want to printf:
I really want to avoid using a single printf() and the whole text in it and using "\n" etc. or using lots of printf() functions (as stated above) for each sentence etc.
You might want to check this out. It is possible to printf like this, all at once, without making the line of code utterly long.
printf(
"A secret password was chosen to protect the credit card of Pancratius, "
"the descendant of Antiochus. Your mission is to stop Pancratius by "
"revealing his secret password. \n"
"The rules are as follows: \n"
"1. In each round you try to guess the secret password (4 distinct digits) \n"
"2. After every guess you'll receive two hints about the password \n"
"HITS: The number of digits in your guess which were exactly right. \n"
"MISSES: The number of digits in your guess which belongs to the "
"password but were miss-placed.\n");
If you still insist on system(), you can do it like this:
system("cmd.exe /c type yourInput.txt");
With this, I wish you good luck on error handling (like file not found, wrong current directory).

How to input of a string which contain '\n' in it

I have created an auto typing bot which simulate characters of string given by user.
My code is this:
printf("Enter speed (wpm) (1 to 11750):");
scanf("%d", &speed);
if(speed < 1 || speed > 11750)
{
printf("\nPlease provide CORRECT DATA\n");
return -1;
}
printf("Paste the String : \n");
gets(exaArray);
exaArrayLength = strlen(exaArray);
relation = (int)11750/speed;
printf("typing will start in 2 sec-\n");
Sleep(2000);
i=pos=0;
while(i<=exaArrayLength)
{
Sleep(relation);
if((exaArray[pos]>96) && (exaArray[pos]<123)) //small letters
{
keycode=0x41 + (exaArray[pos]%97);
smallLetter(keycode); //function for key simulation
}
.....
I am taking input using gets function. This program works fine when I paste text which does not contain Enter. So this program works fine with one paragraph.
But if the user provides more than one paragraph, then it simulates only the first paragraph.
Because gets terminates at '\n'. Which function could take multiple paragraph input and assign it to a string.
This is actually a very hard and complex problem, and not easy to solve in an automated way.
It would seem like reading in a loop would be a good solution, but then you come to the point when there is no more input and the reading function just blocks waiting for more input. The easiest way out of this is to have the user enter the "end of file" key combination (CTRL-D on POSIX systems like Linux or OSX, CTRL-Z on Windows), but the user must then be told to do that.
The problem stems from that your program simply have no idea how much data it is expected to read, and there is no function which is able to, basically, read the users mind when the user thinks "that's it, no more data".
Besides the above solution to have the user give an "end of file", you can use other sequences or special keys or even phrases of input to mark the end, but it all comes down to this: Read input in a loop until users says "no more input".
Well, there is no way for the computer to make a difference between the user pressing enter and the "pasted" string containing newlines. (Technically, pasting something into the console is like typing it.)
If you just don't want the problem to exit after one paragraph but continue, you can do it as commenter alk suggested (loop around the reading function) - then you would need Ctrl+C to exit the program and then there would technically still be one paragraph at a time written. Depends on what you further want to do with the program.
On the other hand, if you want a way for the user to input all text at once and only then process it, you would need to define something other than "newline" as "end of input" marker, for example something like ESC.
You would do this by using getchar instead of gets and manually concatenating each char which is entered this way to a string buffer, and if the character has the value 27 (escape key) for instance, you would end the input loop and start outputting.

Inserting special ascii characters into a file using VBA (excel)

I am fairly new to VBA, but not to coding in general. I have an Excel worksheet, part of which I need to export into a text file. However, to ensure the escape characters don't collide with anything written in the worksheet, and also to match up with how escape characters are handled in other (Java & C) apps at our company, I would like to use the ascii character "thorn".
Some languages that I know, like perl, will simply let you enter an escape character and the ascii number of the symbol. E.g., I could type "\231" in order to get "thorn". It seems this is not supported in VBA. Or if it is, I am not sure how.
Lastly, below is a brief snippet of how I imagine I would implement the code, with just the key statements. If you have a better suggestion, or know why this wouldn't be the best way, please let me know.
Open sFullPath For Output As #1
(... some code to capture the values to be written to the next line of the file ...)
sLine = Join(sValues, <the thorn character>)
Print #1, sLine
The code above would be placed within a loop that would regenerate "sValues", the set of relevant cells in the next row to be printed to the text file.
Thanks so much!
Regards,
Mike
To print an ASCII character using its code number, use the chr() function
Extended ASCII isn't standard across all platforms. For whatever reason, the number needed is 222.
So you would need
sLine = Join(sValues, chr(222))
Print #1, sLine
Try replacing <the thorn character> with Chr(254). Let me know how that goes.

Fortran. Keep reading first word of the document until it matches the input.

Good evening!
I am trying to read a text document in Fortran 95 and do some calculations with the values in it. The document has numerous gas names and certain values of 'A' assigned to them. So essentially it look something like this:
Document 1: gas values.
GAS A1 A2
steam 1 2
air 3 4
I want then the user to input a gas name (variable gasNameIn) and implement while loop to keep searching for the gas until it matches the input. So eg. user inputs 'air' and the program starts reading first words until air comes up. It then read values of A1 and A2 and uses them for calculation. What I did for it is that I opened the file as unit 25 and tried the following loop:
do while(gasName .NE. gasNameIn)
read(25, *) gasName
if (gasName .EQ. gasNameIn)
read(25,*) A1, A2
endif
enddo
but I get an error "End of file on unit 25".
Any ideas on how my while loop is wrong? Thank you!
By the first read statement, you read the name correctly, but Fortran then proceeds to the next line (record). Try to use
read(25, *, advance='no') gasName
If your searched gas was on the last line, you get the end of file error. Otherwise you will have an error when reading A1.
you need to read whole lines as strings and process. This is untested but the jist of it:
character*100 wholeline
wholeline=''
do while(index(wholeline,'air').eq.0)
read(unit,'(a)')wholeline
end do
then if you can count on the the first strings taking up ~7 cols like in the example,
read(wholeline(7:),*)ia1,ia2
What happened is that you read the whole line in as "gasName" and tested the whole line to see if it was equivalent to "gasNameIn". It never will be the same if the data is laid out the way you have in your sample, so you will get to the end of your file before you ever get a match. It has been a while since I've written in Fortran, but in the first loop "gasName" will be undefined. Usually that is a no no in programming.
The answer that got in before I could get mine typed in is the way forward with your problem. Give it a go. If you still have some trouble maybe I'll fire up a Fortran compiler and try my hand at Fortran again. (It's been since the early 90's that I've done any.)
CHEERS!
Hi, here is your code modified a bit, you can pitch what you don't need. I just added a couple of lines to make it a self-contained program. For instance, There is a statement which assigns the value "steam" to "gasNameIn". I think you mentioned that you would have the user enter a value for that. I've also added a "write" statement to show that your program has properly read the values. It is a crude kind of "unit test". Otherwise, I've only addressed the part of the program that your question asked about. Check this out:
character (len=5) :: gasName, gasNameIn
gasNameIn = "steam"
open (unit = 25, file = "gasvalues.txt")
do while (gasName .NE. gasNameIn)
read (25, *) gasName
if (gasName .EQ. gasNameIn) then
backspace (25)
read (25,*) gasName, A1, A2
write (*, *) "The gas is: ", gasName, ". The factors are A1: ", A1, "; A2: ", A2
endif
end do
close (25)
end
Ok, here are a couple of notes to help clarify what I've done. I tried to keep your code as intact as I could manage. In your program there were some things that my fortran 95 compiler complained about namely: the "then" is required in the "if" test, and "enddo" needed to be "end do". I think those were the main compiler issues I had.
As far as your code goes, when your program tests that "gasName" is the same as "gasNameIn", then you want to "backup" to that record again so that you can re-read the line. There are probably better ways to do this, but I tried to keep your program ideas the way you wanted them. Oh, yes, one more thing, I've named the input file "gasvalues.txt".
I hope this helps some.
CHEERS!

Resources