Hi!
It is my first post here, so don't tread on me :)! I want to ask, how to watch result of function?
I don't know what to do with this - I tried "Watch 1", but I can't get satisfied result - I mean see "EQUAL" or "DIFFERENT".
I attached my code here:
#include <LPC21xx.H> #include <string.h> #define NULL 0 enum CompResult{DIFFERENT, EQUAL}; enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ unsigned char ucCounter; for(ucCounter=0; pcStr1[ucCounter]==pcStr2[ucCounter]; ucCounter++){ if(pcStr1[ucCounter]==NULL){ return EQUAL; } } return DIFFERENT; } int main(){ char pcStr1[] = {'a','b','c', NULL}; char pcStr2[] = {'d','e','f', NULL}; enum CompResult{DIFFERENT, EQUAL}; eCompareString(pcStr1, pcStr2); return 0; }
Thank's for help and have a good night ;)!
You would have to assign the result to a variable, and watch that variable.
But take care that the variable doesn't get optimised away!
And note that an embedded microcontroller program should not return from main() - think about where it would return to ...
Andrew Neil
I should do something like this?
x = EQUAL; y = DIFFERENT; int main(){ ... x,y; }
I tried sth like this, but it doesn't work - where I did a mistake?
Tells us next to nothing.
Shown exactly what you tried. Describe exactly what you did with it. Describe what you expected to happen. Describe what actually to happened. What testing/investigation/debugging have you done to account for the discrepancy?
When actual behaviour differs from expected behaviour, first check your expectations.
Ok, so I tried this below (see code). I debuged the program and I wirote to Command Window variable x and then y. I'm expecting a result when pcStr1[] == pcStr2[] then should return EQUAL otherwise DIFFERENT - I want to see this. I saw that for the value x (stands for EQUAL) assign value 0x00000001 for y 0x00000000.
#include <LPC21xx.H> #include <stdio.h> #include <string.h> #define NULL 0 enum CompResult{DIFFERENT, EQUAL}; enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ unsigned char ucCounter; for(ucCounter=0; pcStr1[ucCounter]==pcStr2[ucCounter]; ucCounter++){ if(pcStr1[ucCounter]==NULL){ return EQUAL; } } return DIFFERENT; } int main(){ char pcStr1[] = {'a','b','c', NULL}; char pcStr2[] = {'d','e','f', 'e', NULL}; static volatile int x; static volatile int y; x = EQUAL; y = DIFFERENT; eCompareString(pcStr1, pcStr2); x; y; }
So how do you expect the value of either x or y to get changed by the code you showed?
This is a basic 'C' question - nothing to do with Keil or ARM or microcontrollers.
I think you need to take a step back, get a good 'C' textbook, and work through learning the 'C' programming language on a PC before complicating the issue with embedded microcontrollers
Here are some 'C' learning & reference resources - including a free online textbook: blog.antronics.co.uk/.../
Andrew - I think, I have sth wrong wtih setting in Keil..let me explain.
First code (C online Compiler):
#include <stdio.h> #include <string.h> #define NULL '\0' enum CompResult{DIFFERENT, EQUAL}; enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ unsigned char ucCounter; for(ucCounter=0; pcStr1[ucCounter]==pcStr2[ucCounter]; ucCounter++){ if(pcStr1[ucCounter]==NULL){ return EQUAL; } } return DIFFERENT; } int main(){ char pcStr1[] = {'a','b','c', NULL}; char pcStr2[] = {'a','b','d', NULL}; printf("Resullt: %d\n", eCompareString(pcStr1, pcStr2)); return 0; }
And result it's ok. It shows "1" when Strings are the same, otherwise show "0".
Second code (C++ online Compiler):
#include <iostream> using namespace std; #define NULL 0 enum CompResult{DIFFERENT, EQUAL}; enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ unsigned char ucCounter; for(ucCounter=0; pcStr1[ucCounter]==pcStr2[ucCounter]; ucCounter++){ if(pcStr1[ucCounter]==NULL){ return EQUAL; } } return DIFFERENT; } int main(){ char pcStr1[] = {'a','b','c', NULL}; char pcStr2[] = {'a','b','d', NULL}; cout << "Result: " << eCompareString(pcStr1, pcStr2) << endl; return 0; }
Result above is the same. And here i got the code in Keil:
#include <LPC21xx.H> #include <stdio.h> #include <string.h> #define NULL 0 enum CompResult{DIFFERENT, EQUAL}; enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ unsigned char ucCounter; for(ucCounter=0; pcStr1[ucCounter]==pcStr2[ucCounter]; ucCounter++){ if(pcStr1[ucCounter]==NULL){ return EQUAL; } } return DIFFERENT; } int main(){ char pcSource[] = {'a','b','c', NULL}; char pcDestination[] = {'d','e','f', NULL}; CopyString(pcSource, pcDestination); printf("Result: %d\n", eCompareString(pcStr1, pcStr2));
And when I click to debug (Ctrl + F5) then I can't deub my "main.c" program - it's happens always, when I use:
... #include <stdio.h> ... printf("...", ...); ...