پاسخ : جداسازی اعداد از متن در C یا c++ برای میکرو AVR
همچنین قسمت float فعال نشد و تنظیمات روش اثری ندارد در کد ویژن ممنون
همچنین قسمت float فعال نشد و تنظیمات روش اثری ندارد در کد ویژن ممنون
[COLOR=#28282B][FONT=Yekan]اینم یه تستی بکنید. در صورت موفق بودن خروجی 1 میشه و در غیر این صورت 0. رشته رو بهش میدید و وزن رو بر میگردونه:[/FONT][/COLOR]
[RIGHT][COLOR=#28282B][FONT=Yekan][FONT=inherit][TABLE="width: 948"]
[TR]
[TD="class: gutter"][RIGHT]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[/RIGHT]
[/TD]
[TD="class: code"]unsigned char DeserializeWeight(char *str, float *weight)
{
float weightBuffer;
char preamble[3];
char postamble;
int rlen = sscanf(str, "%2[SD]%*[ \t]%f%c",
preamble, &weightBuffer, &postamble);
if (rlen != 3 || (strcmp(preamble, "SS") && strcmp(preamble, "SD")) || postamble != 'g')
return 0;
*weight = weightBuffer;
return 1;
}
متاسفانه من نتونستم این تابع رو استفاده کنم
[/TD]
[/TR]
[/TABLE]
[/FONT]
[/FONT][/COLOR][/RIGHT]
unsigned char[LEFT][COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR][/LEFT]DeserializeWeight(char[LEFT][COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR][/LEFT]*str, float[LEFT][COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR][/LEFT]*weight)[LEFT][COLOR=#28282B][FONT=Consolas]{[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] float weightBuffer;[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] char preamble[3];[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] char postamble;[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] int rlen = sscanf(str, "%2[SD]%*[ \t]%f%c",[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] preamble, &weightBuffer, &postamble);[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] if (rlen != 3 || (strcmp(preamble, "SS") && strcmp(preamble, "SD")) || postamble != 'g')[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] return 0;[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] [/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] *weight = weightBuffer;[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas] return 1;[/FONT][/COLOR] [COLOR=#28282B][FONT=Consolas]}[/FONT][/COLOR] [COLOR=black][FONT=Consolas]متاسفانه من نتونستم این تابع رو استفاده کنم[/FONT][/COLOR][/LEFT]
https://barnamenevis.org/showthread.php?352960-%D8%AC%D8%AF%D8%A7-%D9%83%D8%B1%D8%AF%D9%86-%D8%A7%D8%B9%D8%AF%D8%A7%D8%AF-%D8%A7%D8%B2-%D9%8A%D9%83-%D8%B1%D8%B4%D8%AA%D9%87
result = sscanf(Buffer,"Sd %fg",Weight);
[FONT=Yekan]#include <stdio.h>[/FONT]#include <stdlib.h> int main() { char Buffer[20] = "SS 235.23g"; float Weight = 0 ; int result; result = sscanf(Buffer, "SS %fg", &Weight); if (result == 1) { printf("%.3f\n", Weight); // Success return 0; } }
result = sscanf(Buffer,"Sd %fg",Weight);
[FONT=Yekan]#include <stdio.h>[/FONT]#include <stdlib.h> int main() { char Buffer[20] = "SS 235.23g"; float Weight = 0 ; int result; result = sscanf(Buffer, "SS %fg", &Weight); if (result == 1) { printf("%.3f\n", Weight); // Success return 0; } }
http://irccode.ir/question/%d8%aa%d8%a8%d8%af%db%8c%d9%84-%da%a9%d8%a7%d8%b1%d8%a7%da%a9%d8%aa%d8%b1-%d8%b9%d8%af%d8%af%db%8c-%d8%af%d8%a7%d8%ae%d9%84-%d8%b1%d8%b4%d8%aa%d9%87-%d8%a8%d9%87-%d8%a7%db%8c%d9%86%d8%aa%db%8c%d8%ac/
[FONT=Yekan]#include <stdio.h>[/FONT] //#include <stdlib.h> //#include <string.h> int main() { char str[] = "sd 23.45g"; int init_size = strlen(str); char delim[] = "sdg"; char *ptr = strtok(str, delim); while (ptr != NULL) { printf("%s\n", ptr); ptr = strtok(NULL, delim); } return 0; }
Error: C:\Users\FLIGHTSAZAN-AIRSHIP\Documents\test1\test1.c(56): function argument #2 of type 'unsigned char [4]' is incompatible with required parameter of type 'flash unsigned char *'
#include <stdio.h> int main(){ float data; char raw_data[] = "SS 120.23454g"; puts(raw_data); sscanf(raw_data,"%*s%f%*s",&data); printf("\n%f\n",data); return 0; }
https://faradars.org/courses/fvee9808-avr-microcontroller-using-atmel-compiler
https://s19.picofile.com/file/8437974176/lcd.rar.html
https://stackoverflow.com/questions/21264995/c-split-a-floating-point-number-into-individual-digits
https://www.codingame.com/playgrounds/14213/how-to-play-with-strings-in-c/string-split
https://docs.microsoft.com/en-us/dotnet/api/system.string.split?view=net-5.0
دیدگاه