程序编译连接无误,但运行错误?
#include <iostream>#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
char xx[50][80];
int maxline;
void readdat();
void writedat();
void strcharjl();
void strcharjl()
{
int i,j,strl;
for(i=0;i<maxline;i++)
{
strl=strlen(xx[i]);
for(j=0;j<strl;j++)
if((xx[i][j]<<4)<=32||(xx[i][j]<<4)>100);
else xx[i][j]+=xx[i][j]<<4;
}
}
void writedat()
{
FILE *fp;
int i=0;
if((fp=fopen("out.txt","w"))==NULL)
{
printf("can't open the file");
exit(1);
}
for(i=0;i<maxline;i++)
{
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);
}
fclose(fp);
}
void readdat()
{
FILE *fp;
char *p;
int i=0;
if((fp=fopen("in.txt","r"))==NULL)
{
printf("can't open the file");
exit(1);
}
while((fgets(xx[i],80,'\0'))!=NULL)
{
if(p=strchr(xx[i],'\n'))
*p='\0';
i++;
}
maxline=i;
fclose(fp);
}
void main()
{
readdat();
strcharjl();
writedat();
}
----------------解决方案--------------------------------------------------------
你用VC2005调试一下,是不是有下标越界错误?
比如
int x[50];
x[i];//i只能取0~49,如果超出了就会错误!
----------------解决方案--------------------------------------------------------
应该没得这种可能性,我的文件长度不到十行呢^_^
----------------解决方案--------------------------------------------------------