Reputation: 1279
I'm trying to find the max and min values of an array. I have 'numArray', which is a string of comma separated numbers (e.g. - 3,5,1,6). I'm using a tokenizer to break them into individual ints and storing them in a separate array. I'm then sorting them and printing the 0th element, however 'nums[0]' prints the whole array in the exact order, as in 3,5,1,6. I tried commenting the sorting part but I still got the whole array. What am I doing wrong? I am a beginner in C++.
CString str = numArray;
int i=0;
int nums[50];
int nTokenPos = 0;
CString strToken = str.Tokenize(_T(","), nTokenPos);
while (!strToken.IsEmpty())
{
int x = atoi(strToken);
nums[i]=x;
strToken = str.Tokenize(_T(","), nTokenPos);
i++;
}
std::sort(nums,nums+50);
int min = nums[0];
CString someStr;
someStr.Format(_T("The minimum number is: %d"), min);
minMaxAvg.SetWindowTextA(str);
Upvotes: 0
Views: 146
Reputation: 63862
the error lies in the fact that your argument to minMaxAvg.SetWindowTextA
is str
when you probably meant to pass someStr
, ie. you are passing the original string instead of your newly formatted one.
minMaxAvg.SetWindowTextA(str); /* <- this */
minMaxAvg.SetWindowTextA(someStr); /* <- should be this */
Upvotes: 1