실행도중 오류 발생

surren의 이미지

#include
int main()
{
FILE *f1;
FILE *f2;
FILE *f3;
FILE *f4;
FILE *f6;
FILE *Text;


unsigned int count = 0;
char Context[30]={0};
char newtext[30]={0};

int i;
int j;

Text = fopen("/mnt/joe.txt","r");
if(Text == NULL) {
printf("file open error \n");}
else
printf("nice open\n");

fseek(Text,67,SEEK_SET);
fread(Context,sizeof(char),29,Text);


while(1)
{
f1 = fopen( "test1.txt" , "w" ) ;
f2 = fopen( "test2.txt" , "w" ) ;
f3 = fopen( "test3.txt" , "w" ) ;
// f4 = fopen( "test4.txt" , "w" ) ;

for(j=0;j<100;j++)
{
fputs("check check check \n",f1) ;
fputs("check check check \n",f2) ;
fputs("check check check \n",f3) ;
fputs("check check check \n",f4) ;
}
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);

system("rm -f test1.txt");
system("rm -f test2.txt");
system("rm -f test3.txt");
system("rm -f test4.txt");

count++;
if(count>1000)
printf("now count = %d \n",count);

system("df /dev/mtdblock7 > ../countfuct.txt");
f6 = fopen( "../countfuct.txt" , "r" );

fseek(f6,67,SEEK_SET);
fread(newtext,sizeof(char),29,f6);

if(strcmp(Context,newtext) != 0)
break;

}
printf("total %d count run \n",count);


return 0;
}

원래 의도는 특정 마운트된 폴더에 파일을 썼다 지운후 용량을 체크하여 기존 용량을 파일로 한후 배열에 저장해서 현제 변화된 용량이 있으면
종료 하는게 의도입니다..잘되다 검사 1017번정도 있음 세그먼트오류가 발생합니다..왜 그런지 못찾겠습니다..도와주세요 ㅜㅜ
그리고 이런방법 말고 다른방법이 있는지도 궁금합니다..먼가 어설퍼서..

divetou의 이미지

코드를 분석해서 댓글을 다는게 아니니, 우선 이점 양해를 부탁드리구요.

Segmentation fault에 가장 효과적으로 대처할 수 있는 방법은 gdb가 아닌가 합니다.
gcc -g 옵션으로 컴파일 한 후, gdb를 돌려보세요~

SEGFAULT가 어디서 발생하는지 알 수 있습니다.

==============================
꿈꾸는소년

익명 사용자의 이미지

open 을 안했는데 close 하네요?

semmal의 이미지

한번 open을 했으면 한번 close를 해야합니다.
100번 open했으면 100번 close해야죠.

f4의 경우 open이 주석처리 되어있는데, close하고 있고,
f6의 경우 open은 했는데 close를 안하고 있습니다.

close(f4)는 주석처리 해주시고,
if(strcmp(Context,newtext) != 0) break;
전에 close(f6)를 해주세요.

직접 안돌려봐서 잘모르겠지만, 그 정도가 일단 눈에 띄네요.

------------------------------
How many legs does a dog have?

surren의 이미지

구문 오류군요..잘됩니다...

댓글 달기

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