basic version of scan ported to C