Article View: comp.sys.mac.programmer.help
Article #16Re: Pointer arithmetic in C?
From: John Caulfield
Date: Mon, 21 Aug 1995 12:21
Date: Mon, 21 Aug 1995 12:21
35 lines
1681 bytes
1681 bytes
In article <adler-2108951328000001@138.244.207.201> adler@informatik.tu-muenchen.de (Martin Adler) writes:
>In article <oylerb-2108950012310001@msp1-5.nas.mr.net>,
>> Back in my Pascal days, I had absolutely no problem writing strings
>> (Str255s) to text files. I would just do something like this:
>>
>> TextToWrite := 'hello, world!';
<snip>
>the following line should be equivalent:
>OSError = FSWrite(LogFileRefNum, Count,(Ptr) &(TextToWrite[1]));
>OSError = FSWrite(LogFileRefNum, Count,(Ptr) (TextToWrite + 1));
<snip>
Assuming that the assignment above was translated into C as
TextToWrite = "hello, world!";
you are passing FSWrite() as it's third parameter a pointer to the string
"ello, world!". Are you _sure_ that's what you want?
Lose the [1] or + 1, which means also lose the & and the parens. Adding one
may have been necessary in Pascal because of the count byte in the string. C
doesn't have one.
Regards,
jpc
John Caulfield
johnpc@omni.voicenet.com
Don't put that in your mouth. You
don't know where it's been. - Your mother
Technical Details
Message-ID:
<johnpc.39.075ECBAC@omni.voicenet.com>Path:
arc1-ca.pugleaf.net!cherryhill08.voicenet.com!johnpcReferences:
<oylerb-2108950012310001@msp1-5.nas.mr.net> <adler-2108951328000001@138.244.207.201>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cherryhill08.voicenet.com!johnpc From: johnpc@omni.voicenet.com (John Caulfield) Newsgroups: comp.sys.mac.programmer.help,comp.lang.c Subject: Re: Pointer arithmetic in C? Date: Mon, 21 Aug 1995 08:21:21 EDT Organization: Voicenet - Internet Access - (215)674-9290 Distribution: world Message-ID: <johnpc.39.075ECBAC@omni.voicenet.com> References: <oylerb-2108950012310001@msp1-5.nas.mr.net> <adler-2108951328000001@138.244.207.201> NNTP-Posting-Host: cherryhill08.voicenet.com X-Newsreader: Trumpet for Windows [Version 1.0 Rev B final beta #4]