Click here to Skip to main content
15,895,256 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String array comparison Pin
jharn31-Jan-11 6:10
jharn31-Jan-11 6:10 
GeneralRe: String array comparison Pin
jharn31-Jan-11 9:03
jharn31-Jan-11 9:03 
GeneralRe: String array comparison Pin
jsc421-Feb-11 0:13
professionaljsc421-Feb-11 0:13 
QuestionRe: String array comparison Pin
David Crow1-Feb-11 8:51
David Crow1-Feb-11 8:51 
AnswerRe: String array comparison Pin
jsc421-Feb-11 23:36
professionaljsc421-Feb-11 23:36 
AnswerRe: String array comparison Pin
Niklas L31-Jan-11 12:31
Niklas L31-Jan-11 12:31 
GeneralRe: String array comparison Pin
jharn31-Jan-11 12:41
jharn31-Jan-11 12:41 
GeneralRe: String array comparison Pin
KP Lee1-Feb-11 2:22
KP Lee1-Feb-11 2:22 
First off, your code looks like it is supposed to be C++, I'm not an expert on this language. I'm going to assume it is something else because I don't see how this would compile.

I agree with the assessment that the code is a mess no matter what language.
The reason why you aren't blowing up with string vl_reg1[16] = {...} is because the variable is first defined with 16 values in an array and then the {} acts like you said
vl_reg1 = new string[15]
, followed by a loop that fills in 15 values into the new array. Like I said, I'm not an expert. That's what it looks like it is doing. As far as I know C++ doesn't have string as a field. The "new" is probably a mistake on my part because that works great in C#, but entails a huge amount of memory management headaches with C++. (Unless the .Net version of C++ fixes that problem as well.) Anyway in C# you can dynamically change the size of an array if you wish. In C# I would probably say string[] vl_reg1 = {...}
I'm assuming your language supports ubounds(). From your error messages, maybe your language doesn't support "=="?

Change your first while to
}while (counter <= vl_reg1.ubounds(0));
In fact, change your whole do loop to:
do{
a = vl_reg1[counter];
tp = counter++;
}while (counter <= vl_reg1.ubounds(0) && arg1 != a);

You don't have any error checking. Immediately after that execute
if (arg1 != a) return -1.;

You have return vl_reg3[bg][tp];
I don't understand how that would even compile. I know what you are trying to do, but this WON'T do it! (At least in any of the languages I know.) vl_reg3 is a string type single array. You are returning a double value from the routine. You can't change types. All of a sudden you are returning a double array setup from a single array string type. No, it won't automagically determine the string field vl_reg3[bg] needs to be converted to a double type array field and pass back that array's number from the tp location. (Which makes no sense either, but that's what it looks like you are trying to do.
Forget the second loop it is total nonsense. vl_reg2 should be a pointer to the array values you want to use, so keep the numbering scheme you've put into it. These numbers should be a 1 to 1 correllation to the positions of the first argument found in vl_reg1.
Set up a new double array. (call it, say "ret_vals")

Instead of the second array, do some more error checking
if (arg2 < 0) return -2.;// This could be the first line of the code if you want.
if (tp > vl_reg1.ubounds(0)) return -3.;
// You passed a valid array value in the first argument but the second isn't defined yet.
b = vl_reg1[tp];
// There isn't a do loop that will do this, write a line for each array you want to use.
if (b == 12) ret_vals = vl_reg12;
// reassigns the ret_vals array to point to the array of values you want to use.
if (ret_vals == null) return -4.;
// you just screwed up the if tests you were supposed to write
if (arg2 > ret_vals.ubounds(0)) return -5.;
// you just passed too big an argument for the return location in the array values you want to use.
return ret_vals[arg2];
GeneralRe: String array comparison Pin
jharn1-Feb-11 4:39
jharn1-Feb-11 4:39 
GeneralRe: String array comparison Pin
jharn1-Feb-11 5:04
jharn1-Feb-11 5:04 
GeneralRe: String array comparison Pin
KP Lee1-Feb-11 10:18
KP Lee1-Feb-11 10:18 
GeneralRe: String array comparison Pin
jharn1-Feb-11 10:40
jharn1-Feb-11 10:40 
GeneralRe: String array comparison Pin
jharn1-Feb-11 10:46
jharn1-Feb-11 10:46 
GeneralRe: String array comparison Pin
KP Lee1-Feb-11 14:00
KP Lee1-Feb-11 14:00 
AnswerRe: String array comparison [modified] Pin
Alain Rist2-Feb-11 7:07
Alain Rist2-Feb-11 7:07 
GeneralRe: String array comparison Pin
jharn2-Feb-11 14:45
jharn2-Feb-11 14:45 
GeneralRe: String array comparison Pin
Alain Rist2-Feb-11 20:30
Alain Rist2-Feb-11 20:30 
GeneralRe: String array comparison Pin
Alain Rist2-Feb-11 22:54
Alain Rist2-Feb-11 22:54 
GeneralRe: String array comparison Pin
jharn3-Feb-11 5:46
jharn3-Feb-11 5:46 
GeneralRe: String array comparison Pin
Alain Rist3-Feb-11 9:39
Alain Rist3-Feb-11 9:39 
AnswerRe: String array comparison Pin
Stuart Rubin1-Feb-11 3:22
Stuart Rubin1-Feb-11 3:22 
AnswerRe: String array comparison Pin
thomas.michaud1-Feb-11 5:57
thomas.michaud1-Feb-11 5:57 
AnswerRe: String array comparison Pin
MarvinMartian1-Feb-11 13:47
MarvinMartian1-Feb-11 13:47 
QuestionReadFile() Problem Pin
goldenrose931-Jan-11 4:12
goldenrose931-Jan-11 4:12 
AnswerRe: ReadFile() Problem Pin
David Crow31-Jan-11 4:18
David Crow31-Jan-11 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.