C 프로그래밍 급한 도움 부탁드립니다.

heavenlyheavens의 이미지

개괄적인 코딩 목적 : SAC.A라는 파일을 읽어들어 double형의 2열로 구성된 데이터 파일을 읽어들어

로직에 맞게 분석하고 출력하는 것, ti, am은 각각 1번째 열, 2번째 열의 수천 줄의 데이터를 읽어들입니다.

다른 부분은 다 괜찮은 것 같은데, exit(-1)삽입시 이탤릭과 볼드로 표시한 부분 바로 위 까지는 잘 되는데

그 줄이 에러가 나네요. 컴파일 시도 문제가 없는데, Debug Assertion Failed! 창이 출력되면서

C:\data\debug\phasepick.exe

File : fscanf.c

Line : 54

Expression : stream !=Null

이라고 출력이 됩니다. fscanf.c는 제가 만든 적이 없는 파일이구요.. VC 자체에 있는 것인지요?

아무래도 표시한 부분이 문제인 듯 한데 전혀 모르겠습니다...

도움 좀 부탁드립니다. 이 부분만 해결되면 일사천리인데...

#include
#include
#include
#include

double PNarrival[ 20 ], PGarrival[ 20 ], SNarrival[ 20 ], LGarrival[ 20 ], RGarrival[ 20 ];
int i, n;
FILE *PNarriv;
FILE *PGarriv;
FILE *SNarriv;
FILE *LGarriv;
FILE *RGarriv;
FILE *sel;
FILE *epi;
double maximum, am, ti, j, k, amplitude;
double ep[ 20 ];
char ar[ 20 ][ 20 ];
char m;
char sac[ 20 ];

int main( void )
{

sel = fopen( "selected.txt" , "rt" );
epi = fopen( "epi_dis.txt" , "rt" );


fscanf( epi , "%lf" , ep );
fscanf( sel , "%c" , ar );
sprintf( sac , " c:\\Data\\%c " , ar );

FILE *SACFILE = fopen( sac , "wt" );

fscanf( SACFILE , "%lf %lf" , &ti , &am );

for( i = 0; i < 5000; i++ )
{
printf( " Cowabunga! " );

if ( ep[ i ] / ti > 7.0 )
{
if ( ep[ i ] / ti < 8.5 )
{
PNarriv = fopen( "PNarriv.txt", "wt" );

if ( ep[ i ] / ti > 8.45 )
{
if ( ep[ i ] / ti < 8.5 )
{

maximum = am;
ti = PNarrival[ i ];

}
}

else
{

if( maximum < am )
{

maximum = am;

ti = PNarrival[ i ];

}

}


fprintf( PNarriv, "%lf", PNarrival[ i ] );
}

}


if ( ep[ i ] / ti > 5.7 )
{
if( ep[ i ] / ti < 7.0 )
{

PGarriv = fopen( "PGarriv.txt", "wt" );

if( ep[ i ] / ti > 6.95 )
{
if( ep[ i ] / ti < 7.0 )

{

maximum = am;

ti = PGarrival[ i ];

}

}

else
{
if( maximum < am )
{
maximum = am;
ti = PGarrival[ i ];
}

}


fprintf( PGarriv, "%lf", PGarrival[ i ] );
}
}


if ( ep[ i ] / ti > 4.0 )
{
if( ep[ i ] / ti < 5.0 )
{
SNarriv = fopen( "SNarriv.txt", "wt" );

if( ep[ i ] / ti > 4.99 )
{
if( ep[ i ] / ti < 5.0 )
{
maximum = am;
ti = SNarrival[ i ];
}

}
else

{

if( maximum < am )

{

maximum = am;

ti = SNarrival[ i ];

}

}

fprintf( SNarriv, "%lf", SNarrival[ i ] );
}
}


if ( ep[ i ] / ti > 3.2 )
{
if ( ep[ i ] / ti < 3.7 )
{
LGarriv = fopen( "LGarriv.txt", "wt" );

if( ep[ i ] / ti > 3.69 )
{
if( ep[ i ] / ti < 3.7 )
{
maximum = am;
ti = LGarrival[ i ];
}
}
else
{
if( maximum < am )
{
maximum = am;
ti = LGarrival[ i ];
}

}
fprintf( LGarriv, "%lf", LGarrival[ i ] );
}
}


if( ep[ i ] / ti > 2.8 )
{
if( ep[ i ] / ti <3.1 )
{
RGarriv = fopen( "RGarriv.txt", "wt" );

if( ep[ i ] / ti > 3.09 )
{
if( ep[ i ] / ti <3.1 )
{
maximum = amplitude;
ti = RGarrival[ i ];

}
}
else
{
if( maximum < am )
{
maximum = am;
ti = RGarrival[ i ];
}
}
fprintf( RGarriv, "%lf", RGarrival[ i ] );
}

}

fclose( PNarriv );
fclose( PGarriv );
fclose( SNarriv );
fclose( RGarriv );
fclose( LGarriv );
fclose( SACFILE );

return 0;
}
}

sonumb의 이미지

fscanf( sel , "%c" , ar );
sprintf( sac , " c:\\Data\\%c " , ar );
->
%c가 아니고 %s입니다.

파일이 여러개가 아니라면,
char ar[20][20]; 이 아니라 char ar[20]; 으로 하셔야겠네요

eiryklav의 이미지

파일을 열 때 쓰기모드로 여셨네요.

그 이전에 사용된 파일은 읽기모드로 열렸구요.

hugyup의 이미지

whitelazy의 이미지

vc라면 IDE 내에서 디버깅할때 실제 파일은 debug 폴더내에서 수행되지만 경로를 프로젝트 루트로 인식합니다.
hugyup님이 링크건 내용이 맞을듯...

...그런데 fscanf함수를 코드중에 쓰셨는데 내가만든건아니다 라고 하신다면...

어떻게 해석해야하나요 ;;

p.s. 아.. fscanf함수말고 c파일은 만든게 아니라는 의미시라면 제가 잘못생각한거군요..

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.