概要
objective-cでズンドコゲッター、やってみた。
実際
サンプルコード
# import <Foundation/Foundation.h>
# include <stdlib.h>
NSString * zundoko(void)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSURL * url = [NSURL URLWithString:@"http://ohijs0.paas.jp-e1.cloudn-service.com/zundoko"];
NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
NSError * error;
NSURLResponse * response;
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString * r = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return r;
}
int main(void)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * str1 = @"ドコ";
NSString * str2 = @"ズン";
NSString * s = @"";
int i = 0;
while (true)
{
NSString * a = zundoko();
if ([a isEqualToString:str1])
{
s = [NSString stringWithFormat: @"%@%@ ", s, str1];
if (i == 4) break;
i = 0;
}
else
{
s = [NSString stringWithFormat: @"%@%@ ", s, str2];
i++;
}
}
s = [NSString stringWithFormat: @"%@%@", s, @"キ・ヨ・シ!"];
[[NSFileHandle fileHandleWithStandardOutput] writeData: [s dataUsingEncoding: NSUTF8StringEncoding]];
[pool release];
return 0;
}