awk and reversing

Hello

I'm writing script in awk that reverse order the fields of every line in file.
My script have problem with spaces - if there is more spaces between fields
in line of file - my script erase them .
I want my script work like command "tac" - how to change it ?

#!/bin/sh

file=$1
awk '
 {        
   for(i=NF;i>0;i--)
     printf("%s " , $i); printf("\n")
 } ' $file

Untested, but something like this might work, depending on your version of awk:

{
   len=length($0)
   for(i=0;i<len;i++) {
        s=substr($0, len - i , 1 )
        printf("%s" , s )
   }
   printf("\n")
}

just as a comparison, this would do the same thing in ruby:

ruby -pe '$_.reverse!' file