ref https://stackoverflow.com/questions/804288/creating-c-formatted-strings-not-printing-them
// Allocates storage
char *hello_world = (char*)malloc(13 * sizeof(char));
// Prints "Hello world!" on hello_world
sprintf(hello_world, "%s %s!", "Hello" "world");
#include "memory.h"
char *snmpCMD = (char*)malloc(999 * sizeof(char));
char *snmpServerIP = "1.1.1.1";
char *oid = "1.3.6.1.4.1.1";
char *ip = "1.1.1.1";
char *parameterOid = "1.3.6.1.9.9.44.1.2.1";
char *dataType = "I";
char *dataValue = "12";
memset(snmpCMD,0,sizeof(snmpCMD));
sprintf(snmpCMD, "snmptrap -v1 -c public %s %s %s 2 3 1000 %s %s %s ", snmpServerIP , oid,ip ,parameterOid,dataType,dataValue);
printf("snmpCMD = %s\n", snmpCMD);
arduino
int ii = 0;
Serial.write("loop start\r\n");
char buf [7];
sprintf (buf, "%06i", ii++);
buf [MAX_SIZE_TRAME-1] = 0;
留言
張貼留言