아두이노와 가변인자 #3
앞에서 가변인자의 대략적인 형식을 배웠다면, 이제 본격적으로 형태를 공부하자. 단순한 문장인데, 앞에 특별한 단어를 삽입해서 출력을 하는 함수이다. #include #include void errorPrintf(char* p, char* fmt, ...) { va_list ap; strcpy(p, "[ERROR] "); va_start(ap, fmt); vsprintf(p + strlen(p), fmt, ap); va_end(ap); } void setup() { Serial.begin(9600); } void loop() { char buf[25]; errorPrintf(buf, "%d %s", 1, "xxx"); Serial.println(buf); delay(1000); } Colored by Co..
2020. 9. 29.