Solution: 1) extract the input int data using the "%" and "/" methods and import the values of each bit into the character array.
2) since the number is imported into the character array from the delimiter to the highest digit, the character array should be in reverse order.
The programming code used is as follows:
# Include <iostream> using namespace STD; void change (INT number, char s []); void main () {int number; char s [50]; cout <"Please input INTEGER:" <Endl; CIN> Number; cout <change (number, s []) <Endl;/* why is this row incorrect: error c2059: syntax error: ']' */} void change (INT number, char s []) {int I = 0, J; char chtemp; while (0! = Number) {s [I] = Number % 10 + '0'; I ++; number/= 10;} s [I] = '\ 0 '; for (j = 0; j <I/2; j ++) {chtemp = s [J]; s [J] = s [i-j-1]; s [i-j-1] = chtemp ;}}
But there is always an error cout <change (number, s []) <Endl;/* why is this line incorrect: Error c2059: syntax error: ']' */
Subsequent changes:
First Change:
Void change (INT number, char s []); changed to Char change (INT number, char s []);
Cout <change (number, s []) <Endl; changed to cout <change (number, S) <Endl;
Void change (INT number, char s []) to Char change (INT number, char s [])
Add the following statement to the change function: Return s [I];
The error is lost, but no data is returned, as shown in the figure below
Later it was changed to: "Change (number, S); cout <S <Endl;: solved the problem.
But I don't know where the error is: 1) the array as a form parameter cannot be passed like this? <So there should be an error in the first change>
2) Is it because cout usage is not allowed?
If a pointer is used:
# Include <iostream> using namespace STD; void change (INT number, char * s); void main () {int number; char * s; cout <"Please input INTEGER: "<Endl; CIN> Number; change (number, S); // cout <* S <Endl; this row is incorrect! Cout <S <Endl;} void change (INT number, char * s) {If (0 = Number) {* s = '\ 0'; return ;} change (number/10, S); // before S, you cannot add "*" while (* s) s ++; * s = Number % 10 + '0 '; // * s = '\ 0 ';}// Compilation is normal, but the program crashes ...... I don't understand. Put it first. Let's see it tomorrow ......
Solve the problem!