| devonrevenge (668) | |||
|
cannot convert char* to char (*)[20] for argument 1 'void proximity (char (*) [20])' i get the jist but somethings wrong heres my code with bits cut ouut.
| |||
|
|
|||
| AbstractionAnon (412) | |||||
|
L12: You're passing the address of the array. L1,34: proximity is declared to receive the array by value. This discrepancy is causing your error. You want to pass the array by reference: L12:
L1,34:
| |||||
|
|
|||||
| Peter87 (3687) | |
| Remove the & on line 12. | |
|
|
|
| devonrevenge (668) | |||
|
well now its complaining about being an array of references, i actual tries not to pass by reference and proximity had just (array) ass its argument but... maybe my function is innefective, i dont see how though here it is
it just couts "once" so i know it works and...it dont | |||
|
|
|||
| Peter87 (3687) | |
The call should look like proximity(brdray);. I'm not sure how I missed that earlier.
| |
|
|
|
| devonrevenge (668) | |||
|
well i guess if that is correct im just sure now that theres a flaw in the function...is sometimes hard to work out whats wrong its not that a difficult code to follow :) just see if the function checks the board gwaaaaaahnn dare ya
| |||
|
Last edited on
|
|||
| TheIdeasMan (1564) | |||||||||||||
|
Is your proximity function, trying to check if there is anything in an adjacent cell on the board? It is hard to tell what you are trying achieve by looking at the code.
I find this description a bit vague as well. If you are searching for a specific char somewhere on the board, then I don't see how your code is going to achieve that. Now some pedantic style police points :+D while (1)Try not to use infinite loops like that - there are situations where infinite loops are OK, but this isn't one of them. Try to think of a valid & logical situation where the loop will end (you don't seem to have any at the moment)- make that the condition in the while loop. Instead of this:
I would prefer this:
If the variables j & s are not going to be used outside the loops, then you can do this:
I also prefer to use variable names like Row & Col instead of s & j. This might save you from an error one day. This:
Can be written:
With this: if ((brdray [s] [j]==b)&&(brdray [m][j]==u))Variables b and u are not defined - your compiler should have told you that. In future, please post the compiler output as well as your code. Edit: I took so long to reply - some of the things I said don't apply anymore. Edit2: Sorry global variables b & u. | |||||||||||||
|
Last edited on
|
|||||||||||||
| Peter87 (3687) | |||
|
You haven't told us why you think anything is wrong with the code. Do you get an error message, or is it not behaving as expected? I don't get why you have all those variables in proximity. Most of them are not even used. The only statement that's inside the inner loop is n=s;. You have to use curly brackets to include all the statements.
I'm not really sure what it's supposed to do but brdray[j+1][j] is not correct because it is out of bounds when j == 19.You shouldn't be so afraid of using longer, more descriptive names, especially for global variables. I mean b and u doesn't give a clue what they are for. They should probably be constants by the way. | |||
|
|
|||
| TheIdeasMan (1564) | |||
With that code - none of variables are defined (you haven't set a value for them. Edit: Some of them aren't declared either, and the function is void - so what were wanting to achieve with that? Edit 2: My bad some are global variables - itself not a good idea. | |||
|
Last edited on
|
|||
| devonrevenge (668) | |
|
ahh okay thanks guys k... im trying to check if the two chars ^ and ! are adjacent to each other they are outside scope as b and u...i been trying lots of things(including == std::b and char *bpointer), i dont get any error messages, i just dont get the satisfactory cout (unless i try a strange experiment) when the two chars are adjacent on the board thanks for the advice on tidy readable code, if i was not getting help and was purley self taught i would never learn the common sense that would help...though this code has temporary bits and pieces in it while i build it, i have not learnt how to plan something yet and just get to it hence the warts | |
|
|
|
| devonrevenge (668) | |||
I made it work!! is the call for the function proximity to check the array brdray an elegant solution or a bodge?
i put some sensible bits in i think it is wise to put the good habits even in practicce code im happy with them too...but tell me is it over complicated is it sensible could you do it better i want to know before i close the thread and feel satisfied...thanks for you help guys am lernin | |||
|
|
|||
| devonrevenge (668) | |
| why is it bad to have global variables in that function ideas man? what would the right thing to do be | |
|
|
|
| TheIdeasMan (1564) | |||
|
OK, so now with your proximity function: You have arguments s & j, but they are set to zero in the for loops. Variables n,m,k,l aren't ultimately used for anything - that is they don't affect the result in any way.
This is just one thing I found via Google:
You could declare the variables in main, then pass them to which ever function needs them. If they will never change, make them const. | |||
|
|
|||
| devonrevenge (668) | |
|
great i wondered when i would get to use const...remininds me i have never used new or static either cheers mr ideas man | |
|
|
|