세그먼트 오류 때문에 질문드려요

익명 사용자의 이미지

int main(void)
{
FILE* fp;
int num = 0, num1;
char buffer[100];
char* ptr;
int n = 0;
int i = 0, j = 0, k = 0, l = 0, count = 0, case1 = 0, t = 0;

process* pro = NULL;
process* t_pro = NULL;

while (1)
{
menu();

scanf("%d", &num1);

switch (num1)
{
case 1:
fp = fopen("proc.txt", "rt");

if (fp == NULL) {
printf("파일 오픈 실패 !\n");
return -1;
}
pro = (process*)malloc(sizeof(process) * getTotalLine());
t_pro = (process*)malloc(sizeof(process) * getTotalLine());

while (i < getTotalLine())
{
fgets(buffer, sizeof(buffer), fp);
if (i != getTotalLine() - 1)
buffer[strlen(buffer) - 1] = '\0';//개행문자 제거
ptr = strtok(buffer, " ");
pro[i].num = atoi(ptr);
t_pro[i].num = pro[i].num;

ptr = strtok(NULL, " ");
pro[i].cpu_t = atoi(ptr); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ptr = strtok(NULL, " ");
pro[i].arrival_t = atoi(ptr);
ptr = strtok(NULL, " ");
pro[i].priority = atoi(ptr);
t_pro[i].cpu_t = pro[i].cpu_t;
t_pro[i].arrival_t = pro[i].arrival_t;
t_pro[i].priority = pro[i].priority;
i++;
}
}
}
}
정확한 곳은 모르겠는데 파일 입출력하니깐
gdb 하니깐
pro[i].cpu_t = atoi(ptr);
이라인 앞뒤쪽에서 죽더라고요 아무리 생각해도 모르겠는데
어떻게 수정해야 되나요...?

비쥬얼스튜디오에서는 잘돌아가는데
리눅스는 다룰줄 몰라서 이유를 모르겠네요 ㅠㅠㅠ

익명 사용자의 이미지

디버그를 하기엔 알 수 있는 게 너무 적군요.
(e.g., getTotalLine 함수는 무엇을 반환하는지, proc.txt 파일에는 무엇이 쓰여 있는지 등등)

하지만 저라면 strtok이 NULL을 반환하진 않는지 먼저 점검해 볼 겁니다. 만약 그게 사실이라면, 입력 파일의 포맷이 막연히 예상한 것과는 다르기 때문일 가능성이 큽니다.

반환값 점검 꼼꼼히 해야 됩니다. 귀찮아보여도 그게 벌어주는 시간이 꽤 되거든요. 아무 정보도 없이 생각만 한다고 문제가 해결되겠습니까?

댓글 달기

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