我正在制作一个应用程序,我正在尝试使用isEqualToString来比较我知道相同的字符串.但是,此代码无效
- (void)uui {
array2 = [NSMutableArray arrayWithContentsOfFile:Path2];
string = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:3]];
NSString *string2 = [NSString stringWithFormat:@"Partly Cloudy"];
NSLog(@"%@ , %@", string, string2);
if ([string isEqualToString:string2]) {
NSLog(@"frack");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在日志中得到的
2013-01-02 23:13:27.512 My Sky[3788:907] Partly Cloudy , Partly Cloudy
Run Code Online (Sandbox Code Playgroud)
如您所见,它们是相同的.我在这做错了什么?
例如,当我键入时,test \n test尝试使用此代码进行编写
FILE *f = fopen(file, "w+");
fflush(f);
if (f==NULL) {
//perror(f);
return 0;
}
else{
int i = fprintf(f, "%s", text);
if (i>0) {
fclose(f);
return 1;
}
else{
fclose(f);
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
然后用它来读它
FILE *f = fopen(file, "r");
static char c[100000];
const char *d;
if (f!=NULL) {
if (fgets(c, 100000, f) !=NULL){
d = c;
}
else{
d = "No text";
}
}
else{
/*
char *ff = f;
perror(ff);
*/
d = "File …Run Code Online (Sandbox Code Playgroud) 当我使用此代码时
FILE *f = fopen(file, "wb");
fflush(f);
if (f==NULL) {
//perror(f);
return 0;
}
else{
fwrite(text, sizeof(char), strlen(text), f);
int i = fprintf(f, "%s", text);
if (i>0) {
fclose(f);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
如果我写的话,(text是const char text[1024000],它被设置为函数中的一个参数)
This is a test
This is a test
Run Code Online (Sandbox Code Playgroud)
为了测试它是否可以写多行,它会写出来
This is a test
This is a testThis is a test
This is a test
Run Code Online (Sandbox Code Playgroud)
为什么我会得到这种奇怪的行为?
我试图在iPhone应用程序中使用zlib将文本文件压缩为gzip文件作为测试.我使用以下代码
const char *s = [[Path stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@".%@", [Path pathExtension]] withString:@".gz"] UTF8String];
gzFile *fi = (gzFile *)gzopen(s, "wb");
const char *c = readFile(Path.UTF8String);
gzwrite(fi, c, strlen(c));
gzclose(fi);
Run Code Online (Sandbox Code Playgroud)
其中readFile()返回const char*一个从使用该文件而获得fgets()的功能.问题是,当我使用它来压缩文件时,它不会压缩它,而是gzip文件比原始文件大.例如,我有一个90字节的文本文件,使用此方法后,gzip的大小为98字节.为什么gzip不比原始文件小?