C 语言字符串倒置,结果不显示
#include <stdio.h>#include <string.h>
unsigned char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */
int ReadDat(void) ;
void WriteDat(void) ;
void ChA(void)
{
int i,j;
char first;
char temp;
for(i = 0; i < maxline; i ++){
first = xx[i][0];
for(j = 0; j < 79; j++){
xx[i][j] = xx[i][j] + xx[i][j+1];
}
xx[i][79] = xx[i][79] + first;
/*for(j = 0; j < 80/2; j++){
temp = xx[i][j];
xx[i][j] = xx[i][79 - j];
xx[i][79 - j] = temp;
}*/
}
}
void main()
{int i,j;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!\n\007") ;
return ;
}
ChA() ;
WriteDat() ; scanf("%d",&i);
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;
if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], '\n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
int i ,j;
fp = fopen("OUT.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%s\n", xx[i]) ;
fprintf(fp, "%s", xx[i]) ;
}
fclose(fp) ;
}
加粗部分去掉注释后,结果只显示一列的字符串,而行向上没有显示。