程序以获取用户的详细信息,计算年龄并显示所有信息

编程入门 行业动态 更新时间:2024-10-21 15:39:50
本文介绍了程序以获取用户的详细信息,计算年龄并显示所有信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经启动了一些代码,但是在将用户字符串输入保存到变量中时遇到问题.

I have some code started but I am having problems saving the users string input into a variable.

使用ReadString可以提示用户输入字符串,但是将用户输入保存到名为AskName1的变量中,然后显示保存在AskName1中的信息后,我发现它可以保存用户的字符数输入而不是实际的字符串.因此,我需要弄清楚的是如何将用户输入的字符串保存到变量中,而不是用户输入的字符数.

Using ReadString I can get prompt the user to input a string, but after saving the users input into a variable named AskName1, and then displaying the information saved in AskName1, I have found that it save the number of characters that the user input and not the actual string. So what I need to figure out is how to save the string that the user input into a variable instead of the number of characters the user input.

INCLUDE Irvine32.inc .data AskName BYTE "Please enter your name " ,0dh,0ah,0 Birth BYTE "Please enter your birth year",0dh,0ah,0 Job BYTE "Pleas enter the location at which you work",0dh,0ah,0 AskName1 DWORD ? Birth1 DWORD ? Job1 DWORD ? .code main PROC call Clrscr mov edx, OFFSET Birth call writestring call ReadInt mov Birth1, eax mov edx, OFFSET Birth1 call writeint call crlf mov edx, OFFSET AskName call WriteString call ReadString ; AT THIS POINT I WANT TO TAKE USER STRING INPUT AND SAVE THE STRING INTO THE VARIABLE "ASKNAME1" main ENDP END main

推荐答案

Irvine的 ReadString 在EDX和ECX中需要两个参数.它填充EDX指向的内存,并返回输入的大小.由于[EDX]中的字符串将以零结尾,因此您必须为该字符串和结尾的null保留空间.使用AskName1 DWORD ?,您仅保留4个字节-肯定不够.

Irvine's ReadString needs two arguments in EDX and ECX. It fills the memory pointed by EDX and returns in the size of the input. Since the string in [EDX] will be zero-terminated, you have to reserve space for the string and the terminating null. With AskName1 DWORD ? you reserved only 4 bytes - that's surely not enough.

如我所见,在调试中,ECX应该是字符串且为null的大小(未提及:最大非null字符数" = size-1) ).

As I saw debugging, ECX should be the size of the string with null (not as mentioned: "max number of non-null chars" = size-1).

这样做:

INCLUDE Irvine32.inc .data ... AskName1 BYTE 16 DUP (0) ; Reserve 16 bytes and fill them with 0 ... .code ... lea edx, AskName1 ; EDX = address of AskName1 mov ecx, Sizeof AskName1 ; ECX = size of AskName1 call ReadString ... ; and don't forget: push 0 call ExitProcess

更多推荐

程序以获取用户的详细信息,计算年龄并显示所有信息

本文发布于:2023-11-17 08:27:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详细信息   年龄   程序   用户   信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!