scanf在scanf的行上产生段错误

时间:2018-11-19 21:40:34

标签: c scanf

<section class="flex__wrapper">
	<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
		<article class="bkg--grey">
			<div class="flex__item">
				<div>
					<h4>Some Efficiently</h4>
					<p>Efficiently enhance frictionless markets without distinctive deliverables. </p>
				</div>
				<div><a href="#">Read More</a></div>
			</div>
		</article>
	</div>
	<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
		<article class="bkg--grey">
			<div class="flex__item">
				<div>
					<h4>Some Objectively promote</h4>
					<p>Objectively promote enterprise-wide strategic theme areas rather than process-centric catalysts for change. Completely procrastinate sticky best practices and corporate sources. Distinctively unleash superior metrics via go forward alignments. Uniquely reconceptualize plug-and-play e-services through collaborative solutions. Progressively maximize adaptive experiences with. </p>
				</div>
				<div><a href="#">Read More</a></div>
			</div>
		</article>
	</div>
	<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
		<article class="bkg--grey">
			<div class="flex__item">
				<div>
					<h4>Completely create</h4>
					<p>Completely create equity invested relationships for client-focused paradigms. Distinctively benchmark exceptional information before corporate materials. Compellingly pontificate 2.0. </p>
				</div>
				<div><a href="#">Read More</a></div>
			</div>
		</article>
	</div>
	<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
		<article class="bkg--grey">
			<div class="flex__item">
				<div>
					<h4>Distinctively deliver</h4>
					<p>Distinctively deliver one-to-one potentialities with excellent resources. Collaboratively.</p>
				</div>
				<div><a href="#">Read More</a></div>
			</div>
		</article>
	</div>
	<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
		<article class="bkg--grey">
			<div class="flex__item">
				<div>
					<h4>Authoritatively facilitate</h4>
					<p>Authoritatively facilitate sustainable portals through cross-platform catalysts for change. Monotonectally transform e-business total linkage without front-end action items.</p>
				</div>
				<div><a href="#">Read More</a></div>
			</div>
		</article>
	</div>
</section>

这是我拥有的代码,我很傻,很可能会错过一个非常基本的错误。它在scanf行上发生段错误。 我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

分段错误不是在scanf处,而是在printf处。正如@TypeIA在注释部分中提到的,这是因为printf期望有一个指向格式字符串的指针,而不是整数本身。为此,就像在使用%d接受整数作为输入时使用格式说明符scanf一样,在使用printf打印时也需要使用相同的格式,即

printf("%d",n);请注意%d之前的n

更新的代码:

#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    printf("%d",n);
    return 0;
}

答案 1 :(得分:0)

像下面这样使用printf()

printf("%d", n);

在使用code之前,您可能在scanf中犯了一个错误。例如,如果您在未初始化的数组中复制一个指向内存中无处的字符串,则可能会发生这种情况。