Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!olivea!mintaka!bloom-beacon!eru!hagbard!sunic!news.funet.fi!uwasa.fi!ts From: ts@uwasa.fi (Timo Salmi) Newsgroups: comp.lang.pascal Subject: Re: Integer to String Conversion Message-ID: <1990Sep26.082929.9182@uwasa.fi> Date: 26 Sep 90 08:29:29 GMT References: <24602@adm.BRL.MIL> Organization: University of Vaasa Lines: 19 In article <24602@adm.BRL.MIL> chaudhury@physics.ucla.edu (CHAUDHURY, SHILADITYA) writes: > I wonder if someone could point out a simple way to do integer to string >conversion in SUN Pascal. I generate a number that needs to be part of a >filename in : There is no trivial solution in a standard Pascal although the resulting code will be brief. Here is the outline. To convert an integer to a string you'll need a loop, which extracts the digits from the integer. This is achieved by using mod. Then you convert a digit by using chr plus ascii for 0. To control the loop and to extract successive digits you must div the integer until the division produces 0. In order for the conversion to be general, you must also test for the sign. It is easier to convert a non-negative integer, and then augment the sign to the beginning of the string. ................................................................... Prof. Timo Salmi (Moderating at anon. ftp site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun