flat assembler
Message board for the users of flat assembler.

Index > Windows > scanf problem

Author
Thread Post new topic Reply to topic
Squalotaku



Joined: 16 Apr 2009
Posts: 2
Squalotaku
Hi every body!
I wrote this following code to read informations et print it on the console but I don't understand why but when i enter an integer for age my prog didn't write the good result :

for example :
Quote:
name: hi
age:45
Hello, hi! What are you having today?Sorry kid, you're only 4202522!


Can you explain to me why this is not working well please?

Code:
format PE CONSOLE
include 'include/win32ax.inc'
entry start ;label d'entrée dans le programme
;================
;section data
;================
section '.data' data  readable writeable
%d     db "%d",0

section '.bss' data  readable writeable
namem:      dt ?
age     dw ?

;================
;section code
;================
section '.code' code readable executable
start:
        invoke       printf, "Name: "
      invoke  scanf, "%s", namem
        invoke  printf, "Age: "
       invoke  scanf, "%d", age
  invoke  printf, "Hello, %s! What are you having today?", namem
        invoke      printf, "Sorry kid, you're only %d!", age
        invoke ExitProcess,0
;================
;section import (win32)
;================
section '.idata' import data readable writeable
      library kernel,'KERNEL32.DLL', msvcrt, 'msvcrt.dll'
     import kernel, ExitProcess,'ExitProcess'
  import msvcrt,\ 
           printf,'printf',\ 
               scanf, 'scanf'
;======FIN=======


    
[/quote]
Post 16 Apr 2009, 15:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17715
Location: In your JS exploiting you and your system
revolution
Use brackets around "age" when you need to read the value and define it as a dword. Also use cinvoke for all the c library (printf, scanf) calls. invoke is for the windows API calls.
Code:
age dd ?
...
        cinvoke  printf, "Sorry kid, you're only %d!", [age]    
Post 16 Apr 2009, 15:46
View user's profile Send private message Visit poster's website Reply with quote
Squalotaku



Joined: 16 Apr 2009
Posts: 2
Squalotaku
Thanks!!! That works very well! ^^ (sorry for my english)
Post 16 Apr 2009, 16:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.