• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to access the value that a pointer is pointing to
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to access the value that a pointer is pointing to


  • Subject: Re: How to access the value that a pointer is pointing to
  • From: "Lawrence Sanbourne" <email@hidden>
  • Date: Sat, 29 Apr 2006 09:54:17 -0500

oneByte actually isn't a pointer here, so you can just do this:

oneByteASCII = oneByte;

The &oneByte refers to the memory address of oneByte. So, &oneByte is
the only thing doing some pointing. oneByte is the actual data.

Larry

On 4/29/06, Phil Faber <email@hidden> wrote:
The following code successfully copies a file, byte-by-byte.  It uses
fread(&oneByte,1,1,fp1) to read in a byte and fwrite(&oneByte,
1,1,fp2) to write that byte back to disc.

I want to be able to analyse the byte before it writes back to disc
but can't see how to see its value.  oneByte is a pointer to the
value - not the value itself.  I need to do something like:

oneByteASCII=(value of byte at pointer 'oneByte')

How can I achieve this? I know this must be a newbie question but I
have a good excuse ... I AM a relative newbie!

Any help would be appreciated.  It would be really great if someone
could convert:

oneByteASCII=(value of byte at pointer 'oneByte')

..to some legal line of code that actually achieves the goal!

Thanks.

Phil


// Used to store currently read byte int oneByte, oneByteASCII;

        // Provide dialogue box to select file
        NSOpenPanel *panel = [NSOpenPanel openPanel];
        int result = [panel runModalForDirectory:nil file:nil types:nil];

        // Put file name into inputFile
        NSString *inputFile = [panel filename];
        NSMutableString *outputFile;

        outputFile = [NSMutableString stringWithFormat: @"%@-A", inputFile];

        // Prepare file pointer to open selected file
        FILE *fp1;

        // Prepare file pointer to write to output file
        FILE *fp2;

        // Set file pointer to selected file
        fp1 = fopen([inputFile UTF8String],"rb");
        fp2 = fopen([outputFile UTF8String],"wb");

        // Read a byte
        fread(&oneByte,1,1,fp1);

        while(feof(fp1)==0)

        {
                // Write the byte
                fwrite(&oneByte,1,1,fp2);

                // ** This is not legal code but shows what I'm trying to achieve
here! **
                oneByteASCII=(value of byte at pointer 'oneByte');

                // Read next byte
                fread(&oneByte,1,1,fp1);
        }

        // Close files
        fclose(fp1);
        fclose(fp2);
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >-[NSAttributedString initWithData:...] compresses spaces? (From: Glen Simmons <email@hidden>)
 >How to access the value that a pointer is pointing to (From: Phil Faber <email@hidden>)

  • Prev by Date: How to access the value that a pointer is pointing to
  • Next by Date: Re: Do I need private accessor methods?
  • Previous by thread: How to access the value that a pointer is pointing to
  • Next by thread: Re: How to access the value that a pointer is pointing to
  • Index(es):
    • Date
    • Thread