Skip to content

Some functions missing like strcasecmp, sprintf, dtostrf ? #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Apr 13, 2015 · 15 comments
Closed

Some functions missing like strcasecmp, sprintf, dtostrf ? #70

ghost opened this issue Apr 13, 2015 · 15 comments

Comments

@ghost
Copy link

ghost commented Apr 13, 2015

Using this function call:

strcasecmp

results in compiler error:

error: 'strcasecmp' was not declared in this scope

same issue for these functions:
sprintf
dtostrf
strtol
ltoa

@chadouming
Copy link
Contributor

have you imported stdio ? cause sprintf works fine here once stdio is imported.

@ghost
Copy link
Author

ghost commented Apr 13, 2015

including the stdio.h fixed the sprintf
but the others still have issues.
tried stdlib.h but didn't help.

@rogerclarkmelbourne
Copy link

dtostrf is an AVR specific function.

Some files from the SAM core of the arduino project need to be added to the cores files

See https://github.com/arduino/Arduino/search?utf8=✓&q=dtostrf

Which shows which files need to be copied to the repo and how they get included

I'm not sure why normal c functions are missing e.g ltoa

Did you try adding your own prototype for these?

@Links2004
Copy link
Collaborator

the functions are implemented and working in the last git version.
to use the functions you need to so the include like this:

extern "C" {

#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>

}

@rogerclarkmelbourne
Copy link

Can't this be added to one of the central includes e.g. Arduino.h ?

@luc-github
Copy link
Contributor

'strtok ' was not declared in this scope

strtok neither strtok_r is found even adding

extern "C" {

#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>

}

I use the arduino-1.6.1-p1-windows.zip which a part this problem works well so far
any way to add it ?

@ghost
Copy link
Author

ghost commented Apr 17, 2015

Some stuff is solved and found some workarounds for others.

But still can't use this one: error: 'strcasecmp' was not declared in this scope
strcmp is ok, strcasecmp is not ?
I guess these should be in the same library? Or it's just not implemented?

@Links2004
Copy link
Collaborator

@luc-github
Copy link
Contributor

Actually I have also used the standalone module of sandeep 0.0.3 which has the file and the modification and still strtok_r is not in scope - I will update the directory like you suggest and feedback later
Thanks for your help

@luc-github
Copy link
Contributor

seems the function is not visible, my test skech is compiling well with a mega board but failed with ESP8266 -

test1.ino: In function 'void loop()':
test1.ino:17:37: error: 'strtok_r' was not declared in this scope
Error compiling.

I have did what was suggested download latest git version - I have the verified that I have the hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c with strtok_r inside =>yes

extern "C" {
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
}
void setup() {
  // put your setup code here, to run once:
}
void loop() {
  // put your main code here, to run repeatedly:
    char * b = strtok_r (NULL,".",NULL);
}

Did I missed something ? Thanks

@Links2004
Copy link
Collaborator

strtok_r is part of the string.h you need to include it.

extern "C" {
#include <string.h>
}

good info base is:
http://www.cplusplus.com/reference/clibrary/

@luc-github
Copy link
Contributor

do not change the result - I have tested before actually and just redid now to confirm and still
'strtok_r' was not declared in this scope
It is weird

even weird is strcat has no issue

@Links2004
Copy link
Collaborator

strange if i try

extern "C" {
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
}
void setup() {
  // put your setup code here, to run once:
}
void loop() {
  // put your main code here, to run repeatedly:
    char * b = strtok_r (NULL,".",NULL);
}

it is compiling.

i add all includes to the Arduino.h and also implement the "strtok" hope this helps.

https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266

@luc-github
Copy link
Contributor

Yes - I must do something wrong somewhere - I will clone the git to avoid to download the zip

Thanks for your time

@ghost
Copy link
Author

ghost commented Apr 18, 2015

I just do not get it to work with strcasecmp. Must have screwed up something somewhere...

Finally decided to include the function into my sketch:

int strcasecmp(const char * str1, const char * str2) {
int d = 0;
while(1) {
int c1 = tolower(_str1++);
int c2 = tolower(_str2++);
if(((d = c1 - c2) != 0) || (c2 == '\0')) {
break;
}
}
return d;
}
At least i can continue and i managed to finish my entire project!
Thanks for this amazing piece of work!

@ghost ghost closed this as completed Apr 18, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants