C언어 질문입니다.

2080fresh의 이미지

#include <stdio.h>
 
int main()
{
	double pos[3];
	double vel[3];
	double t_i = 1;
 
	printf("Initial position r(0) = [x(0) y(0) z(0)] = ");
	scanf("%lf%lf%lf", pos[0], pos[1], pos[2]);
 
	while (t_i != 0)
	{
		printf("\n\tTime interval t_i\t\t= ");
		scanf("%lf", &t_i);
		if (t_i < 0) {
			printf("Please input positive time interval\n");
			continue;
		}
		printf("Velocity\t\t[Vx Vy Vz] = ");
		scanf("%lf%lf%lf", vel[0], vel[1], vel[2]);
 
		for (int i = 0; i < 3; i++) {
			pos[i] = pos[i] + (t_i*vel[i]);
		}
 
		printf("\t\t\tr(%.2f) = [%6.2f%6.2f%6.2f]", t_i, pos[0], pos[1], pos[2]);
	}
 
	return 0;
}

문제는 첨부했습니다.
실행시키면 initialp osition입력은 하라고 하고 입력하면 프로그램이 멈춰버립니다. 컴파일도 문제없이 진행되서 뭐가 문제인지 고민입니다 도와주시면 감사하겠습니다!
File attachments: 
첨부파일 크기
Image icon 캡처.PNG35.4 KB
pynoos의 이미지

scanf("%lf%lf%lf", vel[0], vel[1], vel[2]);scanf("%lf%lf%lf", &vel[0], &vel[1], &vel[2]);
또는
scanf("%lf%lf%lf", vel+0, vel+1, vel+2);
이렇게 해야합니다.
2080fresh의 이미지

그런데 위에 pos를 입력받을때는 &를 안쓰고 왜 거기서는 &를 써야되나요? 그렇게 바꿔도 마찬가지로 frist position을 입력받자마자 프로그램이 멈춥니다.

bushi의 이미지

& 를 써야하는 이유가 궁금한 건가요, 아니면 pos[] 는 왜 지적하지 않느냐는 항의인가요 ?

그래도 멈춘 것 처럼 보인다면, 안 멈췄으니 printf() 가 출력해야 할 것이 '\n' 으로 끝나지 않는 모든 곳에 fflush(stdout) 을 추가하세요.

라스코니의 이미지

debug를 해보시기 바랍니다. 각 라인마다 step-by-step 으로 진행하다 보면 다 직접 해결 하실 수 있습니다. ~~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.