intest

/*
============================================================================
Name : http.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#if 0
#include <stdio.h>
#include <curl/curl.h>

/*
char data[100];
data[0] = '\0'; //BUILD DATA STRING FOR XML REQUEST
strcat(data, "id=");
strcat(data, id);
strcat(data, "&");
strcat(data, "function=");
strcat(data, function);
strcat(data, "&");
strcat(data, "parameter=");
strcat(data, parameter);
*/

char unitid[] = "TEST05";
char buff[51200];

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{

char * pbuf = &buff[0];

memset(buff, '\0', size*nmemb+1);
size_t i = 0;
for(; i < nmemb ; i++){
strncpy(pbuf,ptr,size);
pbuf += size;
ptr += size;
}
printf("XML:\n %s\n",buff);

return size * nmemb;
}

void post_reporting(char *unit_id, int media_id, long time_played, int male0, int male1, int male2, int male3, int female0, int female1, int female2, int female3, int unknown)
{
char data[100];
char temp_char[11];

data[0] = '\0';
strcat(data, "function=P&P=");
itoa(media_id,temp_char);
strcat(data, temp_char);

strcat(data, "&T=");
itoa(time_played,temp_char);
strcat(data, temp_char);

strcat(data, "&R=");
itoa(male0,temp_char); //convert child male
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(male1,temp_char); //convert young male
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(male2,temp_char); //convert adult male
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(male3,temp_char); //convert senior male
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(female0,temp_char); //convert child female
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(female1,temp_char); //convert young female
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(female2,temp_char); //convert adult female
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(female3,temp_char); //convert senior male
strcat(data, temp_char); //join to data string
strcat(data, ","); //CSV input
itoa(unknown,temp_char); //convert unknow audience
strcat(data, temp_char); //join to data string

strcat(data, "&id="); //CSV input
strcat(data, unit_id); //CSV input
strcat(data, "&debug=1"); //DEBUG

printf("data:%s\n", data);

CURL *curl;
CURLcode res;

/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);

/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.200:8888/cms/trunk/update.php");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data); //put returned data in to memory

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();

printf("stuff in memory: \n%s\n",buff);
}

void post_powerup(char *unit_id)
{
char data[100];
char temp_char[11];

data[0] = '\0';
strcat(data, "function=1&id=");
strcat(data, unit_id);

CURL *curl;
CURLcode res;

/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);

/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.200:8888/cms/trunk/update.php");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data); //put returned data in to memory

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();

printf("stuff in memory: \n%s\n",buff);

}

/* BEGIN itoa.c */

void itoa(int, char *);
char *sput_i(int, char *);
char *sput_ip1(int, char *);

void itoa(int integer, char *string)
{
if (0 > integer) {
++integer;
*string++ = '-';
*sput_ip1(-integer, string) = '\0';
} else {
*sput_i(integer, string) = '\0';
}
}

char *sput_i(int integer, char *string)
{
if (integer / 10 != 0) {
string = sput_i(integer / 10, string);
}
*string++ = (char)('0' + integer % 10);
return string;
}

char *sput_ip1(int integer, char *string)
{
int digit;

digit = (integer % 10 + 1) % 10;
if (integer / 10 != 0) {
string = (digit == 0 ? sput_ip1 : sput_i)(integer / 10, string);
*string++ = (char)('0' + digit);
} else {
if (digit == 0) {
*string++ = '1';
}
*string++ = (char)('0' + digit);
}
return string;
}

/* END itoa.c */

int main(void)
{
post_powerup(unitid);

post_reporting(unitid, 377, 1348304373, 0, 1, 2, 3, 0, 1, 2, 3, 10);
return 0;
}
#endif

int main(){
monthly();
}

int monthly(){
int total = 240;//months

float intest_day = 1.83f;
float base = 705000.00f;
float rate = 0.052;

int i=0;
float sum=base;
for(;i<total;i++){
int bak=sum;
sum+=sum*rate/12;
printf("intest month %d; sum: %10.2f intest: %10.2f\n",i,sum, sum-bak);
// if(i%12==0){
// printf("\t\year %d:%10.2f", i/12,sum-base);
// }
}

printf("\n total intest: %f",sum-base);

// printf("Year rate: %10.2f", (sum-base)/base);
return 0;
}

int daily(void)
{

float intest_day = 1.83f;
float base = 14420.00f;
float rate = 1.83f/base;

int i=0;
float sum=base;
for(;i<365;i++){
sum+=sum*rate;
printf("%d : %10.2f\n",i,sum);
if(i%30==0){
printf("\t\tmonth %d:%10.2f", i/30,sum-base);
}
}

printf("\n Year: %f",sum-base);

printf("Year rate: %10.2f", (sum-base)/base);
return 0;
}

上一篇:vue 去除前后空格trim


下一篇:csv,json格式数据的读写