Convert array contents to int?

BGM

Limp Gawd
Joined
Jul 6, 2001
Messages
456
Hi, im writing a c program for uni and my brief is quite restrictive.. basically i have to take int values held in an array from subscripts 'm' and 'n' (defined when the program is run) and print them in order using a recursive function (fine, easy).

Problem comes when i have to print them backwards using the same function but only by interchanging the position of two statements, i can't add / change any code which is annoying me a bit...

So, i thought if i could take the value(s) from the array and instead of printing it straight from it, place it in an integer to manipulate it there might be a bit easier..

anyway, basically i need to know how to take

array [1][2][3][4]

and change it to

int 1234 (or even if u can!)

thank u, and any other ideas would be nice cos this is annoying me as i thought it would be straight forward.. :/
 
You might want to go with a string, which would be easy enough to transverse forward and backward with, even an unsigned long int has its limits. (if im understanding you correctly)
 
Code:
void printInt()
{
     if  (1)
          printIntForward();
     else
          printIntBackward();
}

dunno if thats against the rules or not. but it works
 
cheers guys,

i decided my approach was against the rules.. im gonna see my lecturer cos iv spoken to a few people on my course and they dont seem to be able to do it either :eek:

crazy question

ty :)
 
if you're doing it recursively, your function probably says something like :
Code:
// excuse the ugly pseudocode
recursive_print(other_variables, some_array_index) :
    do_bounds_checking()
    print_array_element(some_array_index)
    recursive print(other_variables, some_array_index+1)

one of these obviously shouldn't be moved - what happens if you swap the other two lines?
 
Back
Top