fgets ? how to ?

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
Post Reply
User avatar
waskol
Flight Lieutenant
Posts: 370
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

fgets ? how to ?

Post by waskol » Tue Aug 28, 2018 4:33 pm

Porting Oric kong to c, I was wondering how it would be possible to achieve a secured string input in C, with osdk.

What I would like to achieve :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h> // for strchr()
 
int my_input(char *Astring, int max_length)
{
    char *inputPosition = NULL;
 
    // read the text entered by the user 
    if (fgets(Astring, Alength, stdin) != NULL)  // no user input error ?
    {
        inputPosition = strchr(Astring, '\n'); // looking for "return"
        if (inputPosition != NULL) // end of line found
        {
            *inputPosition = '\0'; // On remplace ce caractère par \0
        }
        return 1; // no error
    }
    else
    {
        return 0; // error !
    }
}

int main()
{
    char YourName[10];
 
    printf("what's your name ? ");
    my_input(YourName, 10);
    printf("Your name is %s !\n\n", YourName);
 
    return 0;
}
but fgets does not seem to exist in oric C

User avatar
Chema
Game master
Posts: 2270
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: fgets ? how to ?

Post by Chema » Tue Aug 28, 2018 6:11 pm

I think f* functions are not in the library (there is no file or stream support at all).

There was a gets and you can easily implement a secure string input function in c or asm easily.

I may even have one somewhere...

User avatar
waskol
Flight Lieutenant
Posts: 370
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Re: fgets ? how to ?

Post by waskol » Tue Aug 28, 2018 7:40 pm

I do not look specifically for a fgets, with stream support, just something that will do the job.

for asm, I am out : noob inside.
in c, ok, but how. get the char, print it, and block input when max_length is reached ok. I don't feel comfortable enough to do it. mainly when the del key is used to delete a mistake

Post Reply