家でやってもうまくデバッグすることができません。
まずMinGWというソフトをインストールしてデバッグしてみました。
$ gcc -g bad.c
GNU gdb (GDB) 7.4
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /path/example...done.
(gdb) run dic001 text001
Startign program: C :\MinGW\msys\1.0\home\*******\a.exe dic001 text001
[New Thread 7144.0x1d44]
Procram recieved signal SIGSEGV, Segmentation fault.
0x76e17732 in ntdll!RtlEqualSid () from C:Windows\system32\ntdll.dll
という感じで何行目にエラーがあるのかわかりません。
学校のパソコンでやった時はどの関数の何行目に間違いがあるのか出てきました。
また実行したプログラムは以下のものです。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define Max_Length 20
#define Table_Size 127
typedef enum { Empty, Dictionary, Text_File } kind;
typedef struct {
char spell[Max_Length+1];
kind flag;
} item;
item checktable[Table_Size];
int ptr;
main(int argc, char *argv[]){
FILE *f;
if (argc != 3){
printf("引数の個数は二つでなければなりません\n");
exit(1);
}
clear_checktable();
f = fopen(argv[1], "r");
if (f == NULL){
printf("%s: 読むことができません\n", argv[1]);
exit(1);
}
read_in(Dictionary, f);
fclose(f);
f = fopen(argv[2], "r");
if (f == NULL){
printf("%s: 読むことができません\n", argv[2]);
exit(1);
}
read_in(Text_File, f);
fclose(f);
print_out();
exit(0);
}
read_in(FILE *f, kind phase){
int c, k;
char word[Max_Length+1];
c = getc(f);
while (c != EOF){
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'){
k = 0;
while (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'){
if (k > Max_Length) {
printf("単語の長さが長過ぎます\n");
exit(1);
}
if (c <= 'Z')
c += 'a'-'A';
word[k] = c;
c = getc(f);
}
word[k] = 0;
insert_checktable(word, phase);
}
else
c = getc(f);
}
}
clear_checktable(){
int h;
for (h = 0; h < Table_Size; h++)
checktable[h].flag = Empty;
ptr = 0;
}
insert_checktable(char *word, kind phase){
int h, start;
h = 0;
while (h < ptr){
if (strcmp(word, checktable[h].spell) == 0){
if (phase = Dictionary){
printf("辞書中に同じ単語が複数個存在します\n");
exit(1);
}
return;
}
h++;
}
if (ptr == Table_Size){
printf("単語の種類が多過ぎます\n");
exit(1);
}
strcpy(checktable[h].spell, word);
checktable[h].flag = phase;
ptr++;
}
print_out(){
int count, k;
count = pack_checktable();
sort_checktable(count);
for (k = 0; k < count; k++);
printf("%s\n", checktable[k].spell);
}
int pack_checktable(){
int k, h;
for (h = 0; h < ptr; h++){
if (checktable[h].flag == Text_File)
continue;
checktable[k] = checktable[h];
k++;
}
}
sort_checktable(int count){
int k, j, m;
item tmp;
for (k = 0; k < count; k++){
m = k;
for (j = k+1; j < count; j++)
if (strcmp(checktable[j].spell, checktable[k].spell) < 0)
m = j;
tmp = checktable[k];
checktable[k] = checktable[m];
checktable[m] = tmp;
}
}
text001とdic001には
a
という文字が入っています。
OSはwindows7です。
これでは課題が始められません。
どうすればいいのか教えてほしいです。
よろしくお願いします。