chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Platform-specific newline in a string?


From: Dan Webb
Subject: Re: [Chicken-users] Platform-specific newline in a string?
Date: Fri, 4 Feb 2005 11:50:25 -0800

--------Original Message--------

>On Wed, 2 Feb 2005 15:11:30 -0800, Dan Webb <address@hidden> wrote:
>> Hello,
>> 
>> Hello chicken users.  I just started using chicken a couple of weeks ago.
>>  So far it's been great!
>> 
>> Here's my problem:
>> 
>> When I format a string like this:
>> 
>>   (sprintf "~A~%" text)
>> 
>> and then write the string to a file, it writes only a line-feed character
>> to the file.  This is correct only on unix.  Is there any way to write a
>> platform-specific newline to the string?
>> 
>
>Well, is this really what sprintf should do? The actual newline->CRLF
>translation normally happens at the time text-files are actually
>written. I'm not sure whether doing this "internally" is the right way
>to do. Actually writing the result of the expression above *should*
>result in CR/LF being written. Are you operning the destination
>file in text-mode? Call open-output-file with an additional #:text
>argument, like this:
>
>(define p (open-output-file "filename" #:text))
>
>
>cheers,
>felix


Thanks for the suggestion.  It makes sense that the platform-specific
conversion of newline should only occur during file I/O.

So I tried your suggestion, but it still writes just a line-feed
character to the file.  Here's my code:

(define write-text-file (lambda (file-name s)
    (let ([p (open-output-file file-name #:text)])
        (let ([slen (string-length s)])
            (do ((i 0 (+ i 1)))
                ((= i slen))
                (write-char (string-ref s i) p)))
        (close-output-port p))))

(write-text-file "foo.h" (sprintf "~A~%" "hello"))


-- 
Dan Webb
address@hidden






reply via email to

[Prev in Thread] Current Thread [Next in Thread]