• 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
How to access the value that a pointer is pointing to
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to access the value that a pointer is pointing to


  • Subject: How to access the value that a pointer is pointing to
  • From: Phil Faber <email@hidden>
  • Date: Sat, 29 Apr 2006 15:09:23 +0100

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
  • Follow-Ups:
    • Re: How to access the value that a pointer is pointing to
      • From: Patrick Seemann <email@hidden>
    • Re: How to access the value that a pointer is pointing to
      • From: "Lawrence Sanbourne" <email@hidden>
References: 
 >-[NSAttributedString initWithData:...] compresses spaces? (From: Glen Simmons <email@hidden>)

  • Prev by Date: NSScrollView flicker
  • Next by Date: Re: How to access the value that a pointer is pointing to
  • Previous by thread: Re: -[NSAttributedString initWithData:...] compresses spaces?
  • Next by thread: Re: How to access the value that a pointer is pointing to
  • Index(es):
    • Date
    • Thread