一个很奇怪程序溢出的有关问题

一个很奇怪程序溢出的问题
本人用C语言编了个可以把输入的字符串写入data.txt的文件的程序,然后输出特定字符串,可是在VS编译以后,会不知道什么时候程序溢出,一个很奇怪程序溢出的有关问题,然后更奇怪地是,溢出以后再也不会溢出,还是能正常运行

以下是我的程序代码和出错VS的警报,感觉是指针问题,但是我觉得我按照要求调用了啊,应该没有野指针才对啊- -
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define COLTH 100

char filename[] = "data.txt";
void main()//Main function is to get the string
{
char string[11][COLTH];
void sort(char[][COLTH], int, int); int output(char[][COLTH]); void inout(char[][COLTH]);
int i = 0, judge = 0;
printf("Please enter eight strings(a sting`s lenth should be within 100 characters)\n");
for (;;)
{
for (; i <= 7; i++)
scanf("%s", string[i]);
if (getchar() != 10)//test the last character if is a return,if isn`t tell user to input again
{
printf("\aWrong! Please enter 8 strings\n");
i = 0; fflush(stdin);//Clean the buffer and iniviliaze the i
continue;
}
break;
}
fflush(stdin);//Clean the buffer
sort(string, 0, 7);
judge = output(string);
if (judge == 1)//If judge equate 1, print the string back to the stdin
inout(string);
system("pause");
}

void sort(char input[][COLTH], int i, int j)//quicksort algorithm

//sort function is to sort the lenth of the input and return the new array
//i is the minimun sign of the array, j is the maximun sign of the array

{
char key[COLTH];
strcpy(key, input[i]);//Inviliaze the key
int max = j, min = i;
while (i < j)
{
for (; strcmp(key, input[j]) <= 0 && i<j; j--);
if (i != j)
{
strcpy(input[i], input[j]);
strcpy(input[j], key);
}
for (; strcmp(key, input[i]) >= 0 && i<j; i++);
if (i != j)
{
strcpy(input[j], input[i]);
strcpy(input[i], key);
}
}
if (max - min == 0 || max - min == 1)
//If max-min=1 indicate that there is mo number from minimun to maximun
//If max-min=0 indicate that there is no number smaller than the key
return;
else
{
sort(input, min, i);
sort(input, j + 1, max);
}
}

int output(char newstr[][COLTH])//Output function

//In this function output the strings that has benn sorted in a file 

{
FILE *output = NULL; char a;
int i = 0;
printf("\nProgram has benn sorted the lenth of the strings that you input\n");
printf("Now the program will create a file named ""data.txt"" in the root catalog \nof this program!\n");
output = fopen(filename, "r");
if (output == NULL)
{
printf("\n\aThe file doesn`t exist,The data will be written in a new data.txt,enter any key to continue\n");
output = fopen(filename, "w+");
getchar();
for (; i <= 7; i++)
{
fprintf(output, "%s", newstr[i]);
fprintf(output, "%c", '\n');
}
}
else
{
for (;;)
{
printf("\n\aThe file exist,Would you like to write a new data.txt?(y or n)\n");
scanf("%c", &a);
if (a == 'y')
{
output = fopen(filename, "w+");
for (; i <= 7; i++)
{
fprintf(output, "%s", newstr[i]);
fprintf(output, "%c", '\n');
}
break;
}
else if (a == 'n')
{
printf("The pogram will exit");
fclose(output);
output = NULL;//Prevent the free pointer
exit(0);
}
else
{
printf("You have entered a wrong character ,Please enter again");
fflush(stdin);
continue;
}
}

}
fclose(output);
output = NULL;//Prevent the free pointer
return 1;
}

void inout(char newstr[][COLTH])//inout function is to output the input
{
FILE *input = NULL; int i = 0, n = 1;
char print[10][COLTH];//Define a array to store the strings in 1,3,5,7 unit
printf("Next the program will print four strings that in the new order\nThey are:\n");
input = fopen(filename, "r");
if (input == NULL)
{
printf("Reading failed");
return;
}
fseek(input, 0L, SEEK_SET);
for (; i <= 7; i += 2, n+=2)
{
fscanf(input, "%s", print[i]);
printf("str%d %s\n", n, print[i]);
if (i >= 6)
break;
fseek(input, strlen(newstr[i + 1]) + 2, SEEK_CUR);
}
fclose(input);
input = NULL;
}


一个很奇怪程序溢出的有关问题一个很奇怪程序溢出的有关问题
------解决思路----------------------
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。

------解决思路----------------------
断点到这里后,查看堆栈,知道看到自己的代码行,就可以看到是什么溢出了。
------解决思路----------------------
你的快排我感觉有问题
这里两句:
 sort(input, min, i);
        sort(input, j + 1, max);

不是一般都写成:
 sort(input, min, i-1);
        sort(input, i+ 1, max);??