Skip to content

Instantly share code, notes, and snippets.

@rplantiko
Created July 21, 2015 18:22
Show Gist options
  • Save rplantiko/18e8e859175f93454550 to your computer and use it in GitHub Desktop.
Save rplantiko/18e8e859175f93454550 to your computer and use it in GitHub Desktop.
#include "fcgi_stdio.h"
#include <unistd.h>
void print_numbers( double* numbers, int n) {
for (int i=0;i<n;i++) {
printf("%s%.4lf",i>0?",":"",numbers[i]);
}
printf("\r\n");
}
void do_header() {
printf("Content-type: text/plain\r\n\r\n"
"pid: %d\r\n", getpid());
}
int main (int argc, char** argv) {
double x[12] = { 36.7858,68.0403,87.9978,106.0944,127.2410,159.4316,216.7858,248.0403,267.9978,286.0944,307.2410,339.4316 };
while (FCGI_Accept() >= 0) {
do_header( );
print_numbers( x, 12 );
} /* while */
return 0;
}
@rplantiko
Copy link
Author

See http://stackoverflow.com/questions/31525028/printf-swallowing-bytes-in-fcgi-mode
Output using the format specifier %lf will not be performed by programs in fastcgi. When changing the %.4lf to %.4f in the above example, the doubles will be printed as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment