www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/23/01:01:25

From: "Alberto Chessa" <achessa AT fiar DOT finmeccanica DOT it>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: "vsscanf" - Is there an equivalent in DJGPP?
Date: 21 Jul 1998 08:44:50 GMT
Organization: TIN
Lines: 63
Message-ID: <01bdb484$2b966040$92c809c0@chessa>
References: <6ovkg5$jlg$1 AT news4 DOT jaring DOT my>
NNTP-Posting-Host: a-mi26-14.tin.it
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Krian U <krian AT umich DOT edu> wrote in article
<6ovkg5$jlg$1 AT news4 DOT jaring DOT my>...
> I have some code ported over from Borland C to DJGPP that uses "vsscanf",
an 
> sscanf-type function that works with va_lists. Since vsscanf isn't 
> ANSI-standard, I'd like to ask what I could do to get the same result in 
> something that looks [...]
> To clarify myself, my aim is to perform an sscanf on a variable-arg list.

> Anyone can help?
> 
> -Krian
> 

This is my vsscanf():

#include <stdio.h>

int my_sscanf(const char *buffer, const char *fmt, ...);
int vsscanf(const char *buffer, const char *fmt, va_list ap);

int main()
{
  char s1[100]; int d1, d2, x1, n; float f1;
  char test_buffer[]="Test vsscanf 10 23 1.056 f 0x123";

  printf("Source: %s\n", test_buffer);
  n=my_sscanf(test_buffer, "Test %s %d %d %f f %x", &s1, &d1, &d2, &f1,
&x1);
  printf("Result (%d): %s %d %d %f, %#x\n", n, s1, d1, d2, f1, x1);
  return 0;
}
#include <stdarg.h>
#include <libc/file.h>
#include <libc/unconst.h>

int my_sscanf(const char *str, const char *fmt, ...)
{
  int r;
  va_list a=0;
  va_start(a, fmt);
  r=vsscanf(str, fmt, a);
  va_end(a);
  return r;
}

int vsscanf(const char *str, const char *fmt, va_list ap)
{
  int r;                /* This code has been cloned from libc/sscanf.c
(DJ) */
  FILE _strbuf;

  _strbuf._flag = _IOREAD|_IOSTRG;
  _strbuf._ptr = _strbuf._base = unconst(str, char *);
  _strbuf._cnt = 0;
  while (*str++)
    _strbuf._cnt++;
  _strbuf._bufsiz = _strbuf._cnt;
  r = _doscan(&_strbuf, fmt, ap);

  return r;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019