fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. unsigned parseAndCompareDouble(const char* inSTR, const char* inF, const char * expect, const char * outF){
  5. unsigned e = 0;
  6. char buffer[2000];
  7. double a = 0;
  8. if( 1 != sscanf( inSTR, inF, &a ) ) e += 1;
  9. if( (int) strlen(expect) != snprintf(buffer, 2000, outF, a) ) e += 1;
  10. if( 0 != strcmp(expect, buffer) ) e += 1;
  11. return e;
  12. }
  13.  
  14. int main( void )
  15. {
  16. unsigned e = 0;
  17. const char * universalFormat = "%*[^/]/%lf";
  18.  
  19. e += parseAndCompareDouble("X/100", universalFormat, "X/100", "X/%3.0lf");
  20. e += parseAndCompareDouble(" X/100\r\n", universalFormat, "X/100", "X/%3.0lf");
  21. e += parseAndCompareDouble(" X/99\r\n", universalFormat, "X/99", "X/%2.0lf");
  22. e += parseAndCompareDouble(" X / 99 ", universalFormat, "X/99", "X/%2.0lf");
  23. e += parseAndCompareDouble("X/99", universalFormat, "X/99", "X/%2.0lf");
  24. e += parseAndCompareDouble(" \"X/100\"\r\n", universalFormat, "X/100", "X/%3.0lf");
  25.  
  26. if( 0 != e ){ printf( "%2u errors occured\n", e ); }
  27. else{ printf( "all pass\n"); }
  28. return e;
  29. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
all pass