//* data conversion into char arrays using sprintf *

#include <iostream> #include <cstring> #include <cstdlib> using namespace std; int main() { char buffer[80]; int val1; double val2; cin >> val1 >> val2; sprintf(buffer, "int= %d, double= %lf\n", val1, val2); // ^^ char array buffer to write to (do not write more than the buffer length!) // ^^ text - print it // ^^ %magic instructs what variables to insert in-between the text // ^^ %magic - each corresponds to one variable to read // %d for decimal int // %lf for double // ^^ variables passed by value // Warning: messing up the vaiable numebrs and/or their types might result in a program crashing cout << buffer; return(0); } void extract(const char* data, int &num1, double &num2, bool &ok) { ok=false; int bytesread = sscanf(data, "+OK %d %lf", &num1, &num2); if (bytesread>0) ok=true; // checl if reading actually took place }