Conversion from MikroBasic to MikroC - mikroc

Can anyone help me with this conversion from MikroBasic to MikroC?
in MB:
FormattedDataString = text + "," + text1 + "," + text2
my effort in C :
FormattedDataString = (text + "," + text1 + "," + text2);
char FormattedDataString [100];
char text,text1,text2;
Regards
Sarel

What you need is the function strcat. The prototype definition is:
char *strcat(char *to, char *from);
The first line will be to copy text to FormattedDataString using strcpy. The prototype definition is:
char *strcpy(char *to, char *from);
So it's like:
strcpy(FormattedDataString, text);
strcat(FormattedDataString, ",");
strcat(FormattedDataString, text1);
strcat(FormattedDataString, ",");
strcat(FormattedDataString, text2);
Please refer to the help section of MikroC.

Related

How to correctly translate an integer into a string in qt

I have some problems with this code
QTime time = QTime::currentTime();
if (time.hour() > edit_hour)
edit_hour -= edit_hour - time.hour();
if ( time.minute() > edit_minute)
edit_minute -= edit_minute - time.minute();
if (time.hour() < edit_hour)
edit_hour += time.hour() - edit_hour;
if (time.minute() > edit_minute)
edit_minute += time.minute() - edit_minute;
edit1_hour = to_string(edit_hour);
edit1_minute = to_string(edit_minute);
QString text = edit1_hour + ":" + edit1_minute;
After compilation (more precisely attempt) I have got a messege like:
‘to_string’ was not declared in this scope
edit1_hour=to_string(edit_hour);
^~~~~~~~~
How to solve it?

From decimal ASCII number to int character

I want to read a file from an SD card that contains integers. The reading function returns decimal ASCII values between 48 to 57 which corresponds to the characters '0' to '9'. How can I save this character as an integer? This is the code I have now. If I run this code and read '0' from the file, access will be 48 and c as well.
char c;
String chat_id;
int access;
int getaccess(String chat_id) {
String a = "Gebruikers/" + chat_id + ".txt";
if (!SD.exists(a.c_str())) {
return 0;
} else {
myFile = SD.open("Gebruikers/" + chat_id + ".txt");
if (myFile) {
Serial.println("Getting the access number");
access = myFile.read();
myFile.close();
Serial.println("done.");
c = access + 0;
return c;
} else {
Serial.println("error opening " + nummer + ".txt");
}
}
}
If you are reading single digits, then just subtract 48 form the ASCII code and you'll get the number.
Most commonly written as:
int oneDigitNumber = someAsciiCode - '0';

Hex to RGB conversion using farbtastic color picker

I found on two posts on here, 1 on using the farbtastic colorpicker, and another on converting hex to RGB values. I'm trying to return the RGB values but I'm stuck.
It's returning the object from the color picker when I use:
console.log(hex +" in")
But after that I can't get any of the conversion part to work?
Help would deeply appreciated as I've only been learning Javascript for around a month now and have hit a wall after a days worth of research.
My code is below:
$('#colorpicker').farbtastic (function hexToRgb(hex) {
console.log(hex +" in")
var bigint = parseInt(hex, 16);
var r = (bigint >> 16) & 255;
var g = (bigint >> 8) & 255;
var b = bigint & 255;
return r + "," + g + "," + b;
console.log(hexToRgb +" out")
});
Worked it out.
$('#colorpicker').farbtastic(function(hex){
$.throttle(250, true, LevelSliderValueChanged)
redpick = hexToRgb(hex).r;
greenpick = hexToRgb(hex).g;
bluepick = hexToRgb(hex).b;
console.log(hexToRgb(hex).r + " R")
console.log(hexToRgb(hex).g + " G")
console.log(hexToRgb(hex).b + " B")
Updatepick() })
function hexToRgb(hex) {
console.log(hex +" in")
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
console.log(result +" split")
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
} });

Parsing texts between " " on a file to a QString

I have a text file which looks like this:
VariableA = 10 VariableB = 20 VariableC = "Hello World"
The code works fine, but my trouble is getting the text strings between " ".
QStringList Data;
Data << "VariableA = " << "VariableB = " << "VariableC = ";
QStringList Values;
int VariableA;
int VariableB;
QString VariableC;
foreach(const QString &DataToFind, Data) {
QRegExp DataExpression(DataToFind);
int DataStart = DataExpression.indexIn(TextToFind);
if(DataStart >= 0) {
int DataLength = DataExpression.matchedLength();
int ValueSize = 1;
while(TextToFind.at(DataStart + DataLength + ValueSize) != QChar(' ')) {
ValueSize++;
}
QStringRef DataValue(&TextToFind, DataStart + DataLength, ValueSize);
Values += DataValue.toString();
DataStart = DataExpression.indexIn(description, DataStart + DataLength);
} else {
continue;
}
}
VariableA = Values[0].toInt();
VariableB = Values[1].toInt();
VariableC = Values[2];
The issue is that the text on VariableC can have spaces and/or " (double quotes) inside it. So the method I've posted above to retrieve the variables from the file is useless. Since it uses " " to reach end of variable in the file.
How can I retrieve the full text inside the double quotes?
QStringList Data;
Data << "A = " << "B = " << "X = ";
int A;
int B;
QString X;
foreach(const QString &DataToFind, Data) {
QRegExp DataExpression(DataToFind);
int DataStart = DataExpression.indexIn(TextToFind);
if(DataStart >= 0) {
int DataLength = DataExpression.matchedLength();
int ValueSize = 1;
while(TextToFind.at(DataStart + DataLength + ValueSize) != QChar(' ')) {
ValueSize++;
}
QStringRef DataValue(&TextToFind, DataStart + DataLength, ValueSize);
DataStart = DataExpression.indexIn(description, DataStart + DataLength);
} else {
continue;
}
}
This does the work.

I want to pass all the arguments of the sprintf into ivlpp_main using argc and argv. code has same effect or not?

This one is Original.
static void build_preprocess_command(int e_flag)
{
ivlpp_main(argc, argv);
snprintf(tmp, sizeof tmp, "%s%civlpp %s%s -F\"%s\" -f\"%s\" -p\"%s\" ",
pbase, sep, verbose_flag?" -v":"",
e_flag?"":" -L", defines_path, source_path,
compiled_defines_path);
}
This is my code
static void build_preprocess_command_and_run(int e_flag)
{
char **myargv;
int argc, arg;
myargc = 7;
myargv = new char(myargc);
arg = 0;
myargv[arg] = new char (strlen(pbase) + strlen("ivlpp") + strlen(sep) + 2);
sprintf(argv[arg], strlen(pbase) + 2,"s%s%ccivlpp", pbase, sep);
myargv[arg++] = new char (strlen(defines_path) + strlen("-F\”%s\”"));
myargv[arg++] = new char (strlen(defines_path) + strlen("-f\”%s\”"));
myargv[arg++] = new char (strlen(defines_path) + strlen("-f\”%s\”"));
myargv[arg++] = new char (strlen("-p\”%s\”"));
myargv[arg++] = new char (strlen("-v"));
myargv[arg++] = new char (strlen("-L"));
if (verbose_flag) {
//argv[arg++] = "-v";
sprintf("-v");
}
if (!e_flag) {
//argv[arg++] = "-L";
sprintf("-L");
}
snprintf( "-F\"%s\"", defines_path);
snprintf( "-f\"%s\"", source_path);
snprintf( "-f\"%s\"", compiled_defines_path);
ivlpp_main(argc, argv);
}
No. First code is wrong. Second doesn't compile. sprintf has more arguments than the single one you're using. my code on your last question works (this is like a duplicate).

Resources