Mou*_*maa 0 iphone math xcode objective-c
我正在尝试创建一个在目标c中使用%运算符的函数我的函数是:
-(void) image1:(UIImageView *)img1
image10:(UIImageView *)img10
image100:(UIImageView *)img100
score:(NSInteger *)sc
{
NSInteger* s100,s10,s1;
s100 = sc % 100;
s10 = (sc - s100 * 100) % 10;
s1 = (sc - sc % 10);
NSLog(@"%d",s1);
}
Run Code Online (Sandbox Code Playgroud)
但我有错误..你能指导我一些解决方案
NSInteger是一种原始类型.根据环境,它可以是32位或64位有符号整数的类型.
s100的声明是
NSInteger* s100
Run Code Online (Sandbox Code Playgroud)
所以s100是一个指针.取指针的模数是错误的.该行应该是:
NSInteger s100,s10,s1;
Run Code Online (Sandbox Code Playgroud)
sc也应该是NSInteger.如果你真的想要传递一个指向NSInteger的指针,你需要在算术时取消引用它:
s100 = *sc % 100;
s10 = (*sc - s100 * 100) % 10;
s1 = (*sc - *sc % 10);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4737 次 |
最近记录: |