主题:[讨论]好不容易通过调试,运行时又跳出“oxxxxx...““不能read“,高手请指点
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
char xx[20][10];
void readdat();
void writedat();
void jssort()
{
int i,j,k;
int str,half;
char temp;
for(i=0;i<20;i++)
{
str=strlen(xx[i]);
half=str/2;
for(j=0;j<half-1;j++)
for(k=j+1;k<half;k++)
if(xx[i][j]>xx[i][k])
{
temp=xx[i][j];
xx[i][j]=xx[i][k];
xx[i][k]=temp;
}
for(j=half-1,k=str-1;j>=0;j--,k--)
{
temp=xx[i][j] ;
xx[i][j]=xx[i][k];
xx[i][k]=temp;
}
}
}
void main()
{
readdat();
jssort();
writedat();
}
void readdat()
{
FILE *in;
int i=0;
char *p;
in =fopen("IN76.dat","r");
while(i<20&&fgets(xx[i],8,in)!=NULL)
{
p=strchr(xx[i],'\n');
if(p) *p=0;
i++;
}
fclose(in);
}
void writedat()
{
FILE *out;
int i;
system("CLS");
out=fopen("out76.dat","w");
for(i=0;i<20;i++)
{
printf("%s\n",xx[i]);
fprintf(out,"%s\n",xx[i]);
}
fclose(out);
}
#include"string.h"
#include"stdlib.h"
char xx[20][10];
void readdat();
void writedat();
void jssort()
{
int i,j,k;
int str,half;
char temp;
for(i=0;i<20;i++)
{
str=strlen(xx[i]);
half=str/2;
for(j=0;j<half-1;j++)
for(k=j+1;k<half;k++)
if(xx[i][j]>xx[i][k])
{
temp=xx[i][j];
xx[i][j]=xx[i][k];
xx[i][k]=temp;
}
for(j=half-1,k=str-1;j>=0;j--,k--)
{
temp=xx[i][j] ;
xx[i][j]=xx[i][k];
xx[i][k]=temp;
}
}
}
void main()
{
readdat();
jssort();
writedat();
}
void readdat()
{
FILE *in;
int i=0;
char *p;
in =fopen("IN76.dat","r");
while(i<20&&fgets(xx[i],8,in)!=NULL)
{
p=strchr(xx[i],'\n');
if(p) *p=0;
i++;
}
fclose(in);
}
void writedat()
{
FILE *out;
int i;
system("CLS");
out=fopen("out76.dat","w");
for(i=0;i<20;i++)
{
printf("%s\n",xx[i]);
fprintf(out,"%s\n",xx[i]);
}
fclose(out);
}