NO

Author Topic: stupid question  (Read 2009 times)

xpectmore

  • Guest
stupid question
« on: May 26, 2019, 09:58:25 AM »
hi!
I programming from 1992,some about an average of 16 houres per day  .. in several languages,script languages,markup languages,...
never in c++
(in 2009 not sure i download a version of pelles c ,then after i try it i delete it  ::)  )

yesterday using several pdf,chm manuals and stackoverflow  "how to" questions i recode  a purebasic program (a x64 compiler in windows 10 x64)  in a code::blocks program that works , then i tryed TINY C and works too , and now in PELLES C that compile that crap but nothing happening.
This program loads in an output of a bench program, a stress tool to simulate several connection in apache, is about ab.exe.

i have xampp installed standard in C:\xampp\

the program had 2 versions :
one for the command
   "c:\xampp\apache\bin\ab.exe" -l -n 5000 -t 1 http://localhost/0/
(in localhost i have my php framework that i benchmark 10 times and I calculate the average very well in purebasic=the cpu is under 40%)
the another for
  "C:\xampp\apache\bin\ab.exe", "-t 1 -c 10 -k -H -q"Accept-Encoding: gzip, deflate" http://localhost/0/
(what ever in cmd.com or purebasic program i got on this almost 82% of my cpu ,and on c++ compilers 100% !!!)

the script i recoded with what "i learn" from Saturday -24 houres ago to Sunday now is this one:
Quote
/*
#include <iostream>

// run this program using the console pauser or add your own getch, system("pause") or input loop

int main(int argc, char** argv) {
   return 0;
}

*/



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <io.h>
#include <string.h>



int main( void )
{
    float  sum;

   char   psBuffer[128];
   FILE   *pPipe;

        /* Run DIR so that it writes its output to a pipe. Open this
         * pipe with read text attribute so that we can read it
         * like a text file.
         */

   sum=0;
for( int a = 0; a < 10; a = a + 1 ) {

   if( (pPipe = _popen( "c:\\xampp\\apache\\bin\\ab.exe -l -n 5000 -t 1 http://localhost/0/", "rt" )) == NULL )
      exit( 1 );

   /* Read pipe until end of file, or an error occurs. */
 char * pch,* pch2 ,* pch3 ;
       char * start,stop;
   while(fgets(psBuffer, 128, pPipe))
   {

  pch = strstr (psBuffer,"Requests per second:");
     //  if(psBuffer.find("Requests per second:"))
     if(pch!=NULL){
    //    printf(pch);
          //printf(psBuffer);
          start=pch+20;
          pch2 = strstr(pch,"[");
      //    printf(pch2);


          pch3 = strtok (pch,"Requests per second:");
        //  while (pch3 != NULL)
        //  {
            //printf ("%s\n",pch3);


           float fr=atof(pch3);

           sum=sum+fr;

 //printf("%.2f\n",sum);
            //printf("%d\n",sum);

           // printf("%.2f\n", atof(pch3));
           // printf("%.2f\n", sum);


        //    pch3 = strtok (NULL, "Requests per second:");
       //   }


    }

   }

   /* Close pipe and print return value of pPipe. */
   /*
   if (feof( pPipe))
   {
     printf( "\nProcess returned %d\n", _pclose( pPipe ) );
   }
   else
   {
     printf( "Error: Failed to read the pipe to the end.\n");
   }*/
  // printf("%d\n",sum);
}
printf("%.2f\n",sum/10);
system("pause 0");
}



so my stupid question is : what is wrong-why is compiling but never work in Pelles C ?


Thanks
« Last Edit: May 26, 2019, 10:19:50 AM by xpectmore »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: stupid question
« Reply #1 on: May 26, 2019, 01:31:39 PM »
Hello,
There are 2 problems, both apparently not depending from you.
The first is that PellesC, from last release doesn't support anymore the 'text' specifier in file open mode (that is the default), so:
Code: [Select]
if( (pPipe = _popen( "c:\\xampp\\apache\\bin\\ab.exe -l -n 5000 -t 1 http://localhost/0/", "rt" )) == NULL )
Should be
Code: [Select]
if( (pPipe = _popen( "c:\\xampp\\apache\\bin\\ab.exe -l -n 5000 -t 1 http://localhost/0/", "r" )) == NULL )

The second seems a broken _popen implementation in 64bits mode.

Please remove the 't' specifier (that should work with all 'C' compilers anyway), and compile in 32bits mode.
Personally I think that the 't' for text extension should be retained to avoid to broke old code.
If it works for you post the problem as a bug report.
« Last Edit: May 26, 2019, 01:33:55 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

xpectmore

  • Guest
Re: stupid question
« Reply #2 on: May 26, 2019, 02:23:33 PM »
Thank you SO MUCH ! It is work !
I never report it as PELLES C's error ...but only as MY MISTAKE 'cause is from yesterday i "learn c++"  by searching on google phrases as "how to get the program's execution OUTPUT into a string "  then i did copy /paste and i was adapt the code to get converted that purebasic code in c++.
So i don't judge even the result in Pelles C or other compilers  : i just i expose you the meeting of MYSELF and C++  ;D

most difficult for me was this:

Quote
printf("%.2f\n",sum/10);
« Last Edit: May 26, 2019, 02:26:30 PM by xpectmore »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: stupid question
« Reply #3 on: May 26, 2019, 03:45:03 PM »
You're welcome, but ... PellesC isn't C++  ::)
PellesC supports only the old good plain C  ;)
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide