小编phy*_*us9的帖子

无法弄清楚是否有陈述

这是我正在使用的代码,它测试'b'的输入,如果还有其他输入则应输出'Y'.

拜托,没有人问为什么我选择使用'Y'作为假值.

> , <
+++++ +++++
[
    > ----- ----
    < -
]
> ----- --- <


[
    >
    +++++ +++++
    [
            > +++++ +++
            < -
    ]
    > +++++ ++++ <
    . <
]
Run Code Online (Sandbox Code Playgroud)

想要相当于

char c;
c = getchar();
if (c == 'b')
    putchar('Y');
Run Code Online (Sandbox Code Playgroud)

无论我把什么输入程序,我都没有输出(指向文件并将其重写,并且屏幕上没有任何内容)

brainfuck

4
推荐指数
2
解决办法
3072
查看次数

UISwipeGestureRecognizer对角滑动问题

好吧,我有一些代码向视图添加4个识别器,像这样

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
    for(int d = UISwipeGestureRecognizerDirectionRight; d <= UISwipeGestureRecognizerDirectionDown; d = d*2) {
         UISwipeGestureRecognizer *sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
         sgr.direction = d;
    [self.view addGestureRecognizer:sgr];
    }
    [self restore];
    [self populate];
    [self displaymap];
Run Code Online (Sandbox Code Playgroud)

}

和这样的识别器

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
printf("Guesture: %d\n", recognizer.direction);
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)
{
    printf("a\n");
    [self move: 'a'];
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
    printf("d\n");
    [self move: 'd'];
}
else if …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios uiswipegesturerecognizer

3
推荐指数
1
解决办法
888
查看次数

使用calloc()设置char数组,完成后也"释放"数组

我正在尝试设置一个字符串数组(在C中,使用Linux).该数组将包含11个字符串(静态长度).我最初将阵列设置为:

char Answers[10][100];
Run Code Online (Sandbox Code Playgroud)

但在我的代码中,我有一个调用fgets(input,sizeof(input),stdin)的部分.当调用这个fgets()部分时,我的Answers数组的最后一个元素被输入的值覆盖(关于答案在堆栈上的位置?).所以现在我试图"锁定"我用于我的Answers数组的内存.我会用吗?

char Answers=calloc(11*sizeof(char));
Run Code Online (Sandbox Code Playgroud)

要么

通过循环运行 -

char Answers[10];
for(c=0;c<=10;c++)
{
    Answers[c]=calloc(1*sizeof(char);
}
Run Code Online (Sandbox Code Playgroud)

另外,当我完成时,我需要使用atexit()来释放分配的内存...因为我无法在atexit()中传递参数,所以最好的方法是什么?

atexit(Free);

void Free()
{
    free(Answers);
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

c arrays free atexit calloc

1
推荐指数
1
解决办法
2万
查看次数