Xcode:与错误代码 -1 的连接丢失 [英] Xcode: lost connection with Error code -1

查看:52
本文介绍了Xcode:与错误代码 -1 的连接丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段看似微不足道的代码是从教科书中复制的,但在 Xcode 在 scanf() 处获取输入后,程序退出并显示错误代码 -1 并显示连接丢失".

#import int main (int argc, char *argv[]){NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];整数;NSLog(@"请输入您的电话号码:");scanf("%i", &number);如果(数字 <0)数字 = -数字;NSLog(@"绝对值为:%i", number);[池排水];返回0;}

更新

我从头开始重新安装了操作系统.10.8.5 和 Xcode 5 — 仍然是同样的问题.安装Xcode 4.6.3,同样的问题,只是没有错误信息,程序直接退出.

我还在一个新的空白项目中编写了一个全新的程序.该问题仅在调用 scanf 函数时才存在.

解决方案

由于程序需要输入一个整数值,所以我按了键盘(在数字键盘上)上的Enter"键.scanf 方法在按下返回"键后终止用户输入.尽管它们通常都被称为Enter"键,但在这种情况下它们的行为却大不相同.

另外,如果您想使用回车"键,您可以在输入的末尾添加一个正斜杠,然后按回车",这将返回与回车"键相同的结果.

骗我.

This seemingly trivial piece of code is copied from the textbook but after Xcode takes the input at the scanf(), the program exits with error code -1 and says "lost connection".

#import <Foundation/Foundation.h>

int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];

int number;

NSLog(@"Type in your number: ");
scanf("%i", &number);

if (number < 0)
    number = -number;

NSLog(@"The absolute value is: %i", number);
[pool drain];
return 0;

}

Update

I have reinstalled the OS from scratch. 10.8.5 and Xcode 5 — still the same issue. Installed Xcode 4.6.3, same issue, just no error message, the program just exits.

I also wrote a completely new program in a new blank project. The issue again only exists when the scanf function is called.

解决方案

Since the program expects an integer value to be inputted, I was hitting the "Enter" key on my keyboard (on the number pad). The scanf method terminates user input after the "Return" key is pressed. Although they are both often referred to as "Enter" keys, they behave very differently in this context.

Also, if you would like to use the "Enter" key, you can add a forward slash to the end of the input and then press "Enter" which would return the same results as the "Return" key.

Silly me.

这篇关于Xcode:与错误代码 -1 的连接丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆