arduino / arduino/ArduinoCore-API

ANSI-C-like fprintf(), fscanf()

Đang mở
#60 2 bình luận 0 reaction 1 người được giao Được @cmaglie nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
C++
Star
306
Fork
150
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Urgently needed: ANSI-C-like `fprintf()`, `fscanf()`

Actually homebrewed `fprintf_` works fine (SD file checked on PC), just `fscanf_` muddles all up.

Up to now I've used a homebrewed function `fscanf_` but it doesn't work for floats in larger files (>400 elements), neither by 1.6.1 nor by 1.6.3 nor by 1.6.5.

These are the homebrewed functions:

Code:

```cpp
//*******************************************************************************_​**_********
int32_t fscanf_ ( File \* stream, const char fmtstr[], ... ) {
const int32_t MAXSTRSIZE = 1024;
char str[MAXSTRSIZE];
va_list args;
int32_t i=0, cnt=0;
int16_t chr;

va_start(args, fmtstr);

strcpy(str, "");
while ( (stream->available()) && (i < MAXSTRSIZE-1) ) {
chr = stream->read() ;
if (chr>=0 && chr!='\n') {
str[i]=(char)chr;
++i;
}
else break;
}

str[++i] = '\0';

cnt = vsscanf( str, fmtstr, args );
va_end(args);

return cnt;
}

//*******************************************************************************_​**_********

int32_t fprintf_ ( File \* stream, const char fmtstr[], ... ) {
char str[1024];
va_list args;
int32_t num;

va_start( args, fmtstr );
num = vsnprintf(str, sizeof(str), fmtstr, args);
stream->print(str);
va_end( args );

return num;
}

//*******************************************************************************_​**_********
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.