Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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




On 29/04/2006, at 20:24, Phil Faber wrote:

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

int is not one byte, you want char for that, and a better name

	char character = 0;


// 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];

I don't understand why you use a mutable string for the output file name, and your variable names are not clear. Replace with this:


	NSString *inputFilename = [panel filename];

You may need to check that the panel returned a name and not nil, check the docs for NSOpenPanel and add the proper error checking.

Here is how to create a string by appending another string:

NSString *outputFilename = [inputFilename stringByAppendingString:@"-A"];


// 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)

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


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

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

        // Close files
        fclose(fp1);
        fclose(fp2);

I don't have any idea what are you trying to do in this loop - it reads an input file and write the same data to the output file, and you don't do anything with the ascii values :-)


Describe what are you trying to do, maybe Cocoa can do most of the work for you.


Best Regards,

Nir Soffer

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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>)
 >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: Phil Faber <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.