arduino / arduino/Arduino

Improvement of stdio.h functions

Open
#2,715 41 comments 0 reactions 1 assignee Claimed by @cmaglie View on GitHub
Component: Core feature request
Dominant language
Java
Stars
14.6k
Forks
7k
PR merge metrics
No merged PRs in 30d

Description

hi,
I would appreciate if the number of stdio.h functions for file access could be improved.
For file access we basically just have (file).print, println, .write, and just .read (by single bytes).
But fprintf and fscanf would be appriciated, too.

E.g.,that's why I just faked fgets() to something which mimics the ANSI function.
It's been programmed quick and dirty, but IMO it's already an improvement.
You may polish it up for your libs and add it for use by SD if you wish.
```c++
char * fgets ( char * str, int32_t num, File * stream ) {
int32_t i;
i=0;
strcpy(str, "");
while ( stream->available() && (i < num) ) {
str[i]=stream->read() ;
if(str[i] >= ' ') ++i;
else
if(str[i] == '\0') goto ok; // end of string: \0
else
if(str[i] == '\n') { // end of string: CR
//str[i] = '\0'; // optional: overwrite CR by '\0'
str[++i] = '\0'; // insert additional 0-termination after CR (== ANSI C)
goto ok;
}
}
ok: return(str);
}

function call:
char sdata[30];
File myFile;
fgets ( sdata, 20, &myFile );
or
char * sptr;
sptr = fgets ( sdata, 20, &myFile );
```
I just am trying to mimic more functions using multiple variable parameter lists ( ... ) provided by
```
#include
#include
```
e.g.,
```
char * fprintf(File * stream, char fmtstr[], ... )
```
but of course it would be better to access the "real" stdio.h functionality instead of a faked and limited homebrewed one.

ps,
the source code gets always corrupted after uploading it here !! :(

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.