" scanf的"功能让我的整个程序崩溃?

时间:2018-05-17 17:19:13

标签: c crash scanf

我决定将第一个C程序写成一台老虎机。但是,我遇到了一些困难。

scanf("%d", decision);
if (decision == 1)

似乎无论何时使用此部件,整个程序都会崩溃。为什么?

编辑:回答。我忘了在"决定之前加入&符号"。感谢大家!

1 个答案:

答案 0 :(得分:2)

您的问题来自一个简单的错误:您忘记g=sns.clustermap(matrix, col_cluster=False, linewidths=0.9, cmap='coolwarm', row_colors=row_colors)传递private def publishMessagesAttempt(producer: KafkaProducer[String, String], topic: String, messages: Iterable[(String, String)], producerMaxDelay: Long, individualMessageMaxDelay: Long, logger: (String, Boolean) => Unit = KafkaClusterUtils.DEFAULT_LOGGER): Iterable[(String, String)] = { val futureMessages = messages.map(message => (message, producer.send(new ProducerRecord[String, String](topic, message._1, message._2)))) val messageSentTime = System.currentTimeMillis val awaitedResults = futureMessages.map { case (message, future) => val waitFor = Math.max(producerMaxDelay - (System.currentTimeMillis - messageSentTime), individualMessageMaxDelay) val failed = Try(future.get(waitFor, TimeUnit.MILLISECONDS)) match { case Success(_) => false case Failure(f) => logger(s"Error happened when publish to Kafka: ${f.getStackTraceString}", true) true } (message, failed) } awaitedResults.filter(_._2).map(_._1) } 的地址而不是其值:

&

请注意,可以通过提高编译器的警告级别来避免此类错误:decisionscanf("%d", &decision); gcc -Wall

另请注意,您应该检查clang -Weverything的返回值。如果号码已正确转换为cl /W4,则应返回scanf()。否则使用1可能会有未定义的行为。