Retrieving values as text, back to numeric values

7 views
Skip to first unread message

paul.s...@telenet.be

unread,
Jan 9, 2023, 2:41:46 PM1/9/23
to filtermeister
Hi All,


Writing values to a file as text separated with a comma works fine.
But for the inverse I can use some help:
retrieving these text values, one by one, and addressing them as a numeric value back to a variable, sounds unclear for me. I couldn't find anywhere a usefull demo...
Can somebody give me an example of (pseudo)code that will do? Thanks ahead!


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    iv00 =fopen( "C:\\FM\\Data\\Info_00.txt","w");    // This writes the values to a text file
////////////////////////////////////////
    for( y =0; y <Y; y++) {
    for( x =0; x <X; x++) {
////////////////////////////////////////
    iA0 =getArray( 0, x, y, 0);
    if( x ==X -1) {
    fprintf( iv00, "%d\n", iA0); }    // new line
    else {
    fprintf( iv00, "%d,", iA0); }    // comma separator
////////////////////////////////////////
    }}  // End_for_y, x
////////////////////////////////////////
    fclose( iv00);


And gives something like this as result:
24312,24365,24896,20774,17107,18041,17273, ...

Ognen

unread,
Jan 9, 2023, 7:10:46 PM1/9/23
to FilterMeister Mailing List (FMML)
Hi Paul and a Happy New Year,
I don't know what your idea is in all this, but isn't it easier to write the value directly into the variable when you need it?
Maybe more explanation on what you want to achieve would make things clearer.

Regards,
Ognen

paul.s...@telenet.be

unread,
Jan 10, 2023, 7:09:22 AM1/10/23
to filtermeister
Hi Ognen,


Thanks for reponse!
It's for a study. The stored values as text could be reed and fed into Excel for further evaluation.

What I want is to reload some selected values back into FM. Thus reading a list of numbers in text format and feeding them to a selection of variables. I only need to know how to convert values as text into a number and how to shift the list.


Grtz,
Paul

Van: "Ognen" <gog...@gmail.com>
Aan: "FilterMeister Mailing List (FMML)" <filter...@googlegroups.com>
Verzonden: Dinsdag 10 januari 2023 01:10:46
Onderwerp: [FMML2] Re: Retrieving values as text, back to numeric values

--
You received this message because you are subscribed to the Google Groups "FilterMeister Mailing List (FMML)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to filtermeiste...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/filtermeister/309fdbaf-5de6-43a8-ac51-5aeefd3a7c31n%40googlegroups.com.

paul.s...@telenet.be

unread,
Jan 11, 2023, 12:44:05 PM1/11/23
to filter...@googlegroups.com
Hi All,
Ognen,


e.g.  24312,24365,24896,20774,17107,18041,17273, ...
What I want to obtain could be reduced to:

1.  Reading text blocks separated with a comma
2.  Converting the retrieved numbers as text back to integers

Eventually could I write first fixed text blocks as the equivalent of 4 bytes,
filled with binary numbers (as text),
if this would work easier to retrieve?

Hopefully this opens up a more viable solution?


Thanks,
Paul

Van: "paul simoens" <paul.s...@telenet.be>
Aan: "filtermeister" <filter...@googlegroups.com>
Verzonden: Dinsdag 10 januari 2023 13:09:19
Onderwerp: Re: [FMML2] Re: Retrieving values as text, back to numeric values

Ognen

unread,
Jan 12, 2023, 6:30:22 PM1/12/23
to FilterMeister Mailing List (FMML)
All I know for now is that you can't do it in FM, but maybe you will extract some information from the example below and will find it useful:

You have to use sscanf() function, which is supported by FM(only in 32bit version as well as the others that belong to stdio.h), but array functions such as getArray() aren't supported and it behaves very odd when you use it.

Regards,
Ognen

Roberto

unread,
Jan 12, 2023, 7:23:46 PM1/12/23
to filter...@googlegroups.com
Hi Paul,

On page 58+ of the FilterMeister Reference (epub file) are numerous file i/o functions described.
Nothing of any use there?

Roberto


Op Wed, 11 Jan 2023 18:44:02 +0100 schreef <paul.s...@telenet.be>:
--
Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/

paul.s...@telenet.be

unread,
Jan 13, 2023, 6:18:37 AM1/13/23
to filtermeister
To Duncan, Ognan, Roberto and others,


Thanks for your reactions.
I have unfortunately little experience with coding of characters. Meanwhile I spent already days of trying things without any or reliable results. Although I'm convinced there must exist simple and elegant tricks to transfer characters back to integers?

Integers could be transferred and stored as text in little more than one line of code.
Is there e.g. nothing like converting characters into their VK_CODE? This would already do the job for me, certainly if I should use binary numbers. This would also allow a constant shift for reading the data. Again, to try this myself, characters and pointers are a grey zone for me, mostly due to the lack of completed examples that really work. If somebody could help me with this?


Another thing: Automatic naming?
When storing data as text, it would be comfortable if the name of the file could be automatic change to avoid overwriting. I found this chunck of code on the web, but I didn't succeed either to let it work in FM, although - as far I can judge - it uses code that is supported by FM.

    void RecordNumber()
    {
    srand( time( NULL) );
    FILE *fp;
    char name[ 64];
    int x,y;
    long num[ 256];
    int na =rand( );

    sprintf( name, "num[%d].dat", na);
    fp =fopen( name,"w");            // fp =fopen( name,"a");
    fclose( fp);
    }

    int main( ) {
    RecordNumber( );
    return 0;
    }

I don't expect a direct reply on this, but it would be great if somebody could find - inbetween the own activities - a working solution. And that can be added to the FM code snippets for general profit of all.


Regards,
Paul

Van: "Duncan Suss" <dunc...@gmail.com>
Aan: "paul simoens" <paul.s...@telenet.be>
Verzonden: Donderdag 12 januari 2023 02:15:48
Onderwerp: Re: [FMML2] Re: Retrieving values as text, back to integers

Hi Paul,

I don't know if FM has implemented the C function strtok, but I found this code snippet on stackoverflow which might point you in the right direction. I think you would have to first allocate a buffer, then read the line of text into the buffer, then parse the buffer contents using strtok. (Perhaps - it's been a long time since I wrote any code in FM or C.)

Best regards,

Duncan

#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="hello, world, I, 287876, 6.0" ;
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str,",");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, ",");
  }
  return 0;
}


Reply all
Reply to author
Forward
0 new messages