• 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: char array not terminating
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: char array not terminating


  • Subject: Re: char array not terminating
  • From: Daniel Jalkut <email@hidden>
  • Date: Tue, 3 Jan 2006 01:10:25 -0500

Michael - you're XOR'ing the null byte at the end of the string - so it's no longer null. You probably want to change your for loop test to "i < 3", for example in this test case.

Daniel

On Jan 3, 2006, at 12:47 AM, Michael Hanna wrote:

I want to be able to XOR a char array, but it doesn't seem to be terminating properly any ideas how to do this?

Michael


char * foo; foo = malloc(4);

        char tempFoo[] =
        {        'f'^0xc2,
                'o'^0xc2,
                'o'^0xc2,
                0x0
        };

        memcpy(foo, tempFoo, 4);

        for(i = 0 ; i < 4 ; i ++)
        {
                tempFoo[i] = tempFoo[i]^0xc2;
        }


printf("foo %s\n", foo);
printf("tempFoo %s\n", tempFoo);
NSLog(@"tempFoo, %@", [NSString stringWithUTF8String:tempFoo]);


foo \244\255\255
tempFoo foo\302
2006-01-02 19:07:19.958 GuitarPrompter[2710] tempFoo, (null)



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


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: 
 >char array not terminating (From: Michael Hanna <email@hidden>)

  • Prev by Date: MVC Alternatives?
  • Next by Date: Re: Agent Applications and launchd
  • Previous by thread: char array not terminating
  • Next by thread: MVC Alternatives?
  • Index(es):
    • Date
    • Thread