Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <string.h>
  2. String temp;
  3. char a[100];
  4. char tempo[100];
  5.  
  6. void setup() {
  7. Serial.begin(9600);
  8. }
  9. void printer(char input[]){int count=0;char temp[100];int answer;
  10. for(int i=0;i<strlen(input);i++){
  11. if(input[i]=='\n'){count++;}
  12. }
  13. if(count==2){
  14. int i=0;
  15. while(input[i]!='\n'){i++;};
  16. substring(input,temp,0,i++);
  17. answer=ToInt(temp);
  18. substring(input,temp,i,strlen(input)-1-i);
  19. answer+=ToInt(temp);
  20. Serial.println(answer);
  21. String empty=" ";
  22. empty.toCharArray(a,empty.length());
  23.  
  24. }
  25.  
  26. }
  27. int ToInt(char input[]){
  28. int i=0;int q=1;
  29. int j;
  30. if(input[0]=='-'){j=1;q=-1;}
  31. else{j=0;q=1;}
  32. for(j=j;j<strlen(input);j++){
  33. i=i*10+(input[j]-'0');
  34. }
  35. return q*i;
  36. }
  37.  
  38.  
  39. void substring(char s[], char sub[], int p, int l) {
  40. int c = 0;
  41.  
  42. while (c < l) {
  43. sub[c] = s[p+c];
  44. c++;
  45. }
  46. sub[c] = '\0';
  47. }
  48.  
  49. void loop() {
  50. while(Serial.available()==0){}
  51. temp=Serial.readString();
  52. Serial.print(temp);
  53. temp=temp+'\n';
  54. temp.toCharArray(tempo,temp.length());
  55. strcat(a,tempo);
  56. printer(a);
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement