OSDK C and the scanf() function

Questions, bug reports, features requests, ... about the Oric Software Development Kit. Please indicate clearly in the title the related element (OSDK for generic questions, PictConv, FilePack, XA, Euphoric, etc...) to make it easy to locate messages.

User avatar
astrofra
Private
Posts: 7
Joined: Tue Jan 06, 2015 7:56 pm
Location: Orleans | France
Contact:

OSDK C and the scanf() function

Post by astrofra »

Hello,

I'm quickly testing C programming in OSDK 1.11 and want to use the scanf() function.
Has anyone tried it before ?

I'm testing the following :

Code: Select all

//
// Using the Scanf() ANSI-C function
//

#include <stdio.h>

void main()
{
	char my_str[256];
	printf("What is your name ?\n");
	scanf("%s", my_str);
	printf("Hello %s!\n", my_str);
}
However, at the moment I get the following answer from the linker :
Building the program HWSIMPLE at adress $800
Compiling MAIN.C
- preprocess
- compile
- convert C to assembly code
- cleanup output
Linking
D:\apps\dev\osdk\sample\c\scanf
Assembling
ldx #262
D:\apps\dev\osdk\sample\c\scanf\MAIN.s(3): 08bd:Overflow error
scanbuf reserve 256
D:\apps\dev\osdk\sample\c\scanf\scanf.s(8): 090d:Syntax error
fieldcount db 0
D:\apps\dev\osdk\sample\c\scanf\sscanf.s(53): 0973:Syntax error
numberscan dw 0
D:\apps\dev\osdk\sample\c\scanf\sscanf.s(166): 0a42:Syntax error
signscan db 0
D:\apps\dev\osdk\sample\c\scanf\sscanf.s(167): 0a42:Label defined error
Break after 5 errors
ERROR : Build failed.
Press any key to continue . . .
Dear Oric fellows, any idea of what I'm doing wrong? (attached is my C tiny program)
Attachments
scanf.zip
(3.07 KiB) Downloaded 368 times
User avatar
Dbug
Site Admin
Posts: 4438
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: OSDK C and the scanf() function

Post by Dbug »

Hello!

As it happens, you are probably the first person having tried to use scanf in the OSDK since we switched to XA instead of FRAsm.

Basically we forgot to convert the syntax for the scanf.s and sscanf.s files in the lib folder.
I just fixed that, but until I release a new version of the OSDK you need to use a temporary fix:
- reserve -> .dsb
- db -> .byt
- dw -> .word
I attached the working files in the zip file.

Also, your overflow error is not something that can be fixed, you have added a 256 bytes local variable in your main, that's not going to work very well.
If you move the "char my_str[256];" out of main() that should work just fine.
FraScanf.png
Attachments
scanf.zip
(1.37 KiB) Downloaded 385 times
User avatar
ibisum
Wing Commander
Posts: 1643
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: OSDK C and the scanf() function

Post by ibisum »

Hey, do either of you guys know if either sscanf or scanf are workable ways to get a hexadecimal number input from the user? I'm trying to use them but not sure whats I'm not quite getting right ..

Code: Select all

			char in[32];
			int v;
			printf("P:");
			v=scanf("%x", in);
			printf("\nin:%s v:%d", in, v);
Produces:

P:(I input)BEEF
in: v:1


EDIT: never mind, I figured it out:

Code: Select all


			unsigned int v;
			printf("P:");
			scanf("%x", &v);
			printf("\nv:%x", v);
Post Reply