We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 ;)!
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("...", ...); ...