קורס RB10 , רובטיקס בלוקס : תרגול 006 –תרגול מחרוזות 1 ו UART esp32
תרגול ולימוד
- מחרוזות
- פונקציה על מחרוזות
- חיבור מחרוזות
- בדיקת מחרוזת
1.מחרוזות :
https://wokwi.com/projects/349662995942474324
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
char msg[100]; char name[30]; char students0[30]; char students1[30]; char students2[30]; char students3[30]; void setup() { int i; // counter // put your setup code here, to run once: Serial.begin(115200); Serial.println ("----------------------------"); strcpy(msg,"RoboTronix.co.il"); Serial.print("Hello :"); Serial.println(msg); strcpy(students0,"Rotem"); strcpy(students1,"Matan"); strcpy(students2,"Noga"); strcpy(students3,"Eraz"); Serial.print ("0"); Serial.print (" "); Serial.println (students0); Serial.print ("1"); Serial.print (" "); Serial.println (students1); Serial.print ("2"); Serial.print (" "); Serial.println (students2); Serial.print ("3"); Serial.print (" "); Serial.println (students3); strcpy(msg,"temp : "); strcat(msg,"27.c"); Serial.println ("----------------------------"); Serial.println (msg); } void loop() { // put your main code here, to run repeatedly: delay(10); // this speeds up the simulation } |
בדיקת מחרוזת ל STRCMP :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
char msg[100]; char name[30]; char students0[30]; char students1[30]; char students2[30]; char students3[30]; void setup() { int i; // counter // put your setup code here, to run once: Serial.begin(115200); Serial.println ("----------------------------"); strcpy(msg,"RoboTronix.co.il"); Serial.print("Hello :"); Serial.println(msg); strcpy(students0,"Rotem"); strcpy(students1,"Matan"); strcpy(students2,"Noga"); strcpy(students3,"Eraz"); Serial.print ("0"); Serial.print (" "); Serial.println (students0); if(strcmp (students0,"Rotem") ==0) { Serial.println ("Happy birthday"); } Serial.print ("1"); Serial.print (" "); Serial.println (students1); if(strcmp (students1,"Rotem") ==0) { Serial.println ("Happy birthday"); } Serial.print ("2"); Serial.print (" "); Serial.println (students2); if(strcmp (students2,"Rotem") ==0) { Serial.println ("Happy birthday"); } Serial.print ("3"); Serial.print (" "); Serial.println (students3); if(strcmp (students3,"Rotem") ==0) { Serial.println ("Happy birthday"); } strcpy(msg,"temp : "); strcat(msg,"27.c"); Serial.println ("----------------------------"); Serial.println (msg); } void loop() { // put your main code here, to run repeatedly: delay(10); // this speeds up the simulation } |
1.מחרוזות ומערך רב מימדי
לימוד מחרוזות מערך חד מימדי ודו מימדי
https://wokwi.com/projects/349662995942474324
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
char msg[100]; char name[30]; char students[5][30]; void setup() { int i; // counter // put your setup code here, to run once: Serial.begin(115200); Serial.println ("----------------------------"); strcpy(msg,"RoboTronix.co.il"); Serial.print("Hello :"); Serial.println(msg); strcpy(students[0],"Rotem"); strcpy(students[1],"Matan"); strcpy(students[2],"Noga"); strcpy(students[3],"Eraz"); for(i=0;i<=4;i++) { Serial.print (i); Serial.print (" "); Serial.println (students[i]); } strcpy(msg,"temp : "); strcat(msg,"27.c"); Serial.println ("----------------------------"); Serial.println (msg); } void loop() { // put your main code here, to run repeatedly: delay(10); // this speeds up the simulation } |
בדיקת מחרוזת