#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char data[10001][10001];
int output(int x,y)
{
int i,j;
for(i=0;i<=x;i++)
{
for(j=0;j<y;j++)
{
printf("%c",data[x][y]);
}
}
}
int main()
{
FILE *fp = fopen("test.txt","w+");
/*the FILE I/O starting x=line y=list*/
int x=0,y=1;//x指向栈顶的下一个元素
char buff;
for(;;)
{
buff = getch();
/*meaning-changed char or normal-char*/
if(buff == '\b' && (x>0||y>1))
{
/*backspace or backline*/
if(y>0)
{
data[x][--y] = 0;
}
else
{
x--;
y = strlen(data[x]);
output(x,y);
}
}
else if(buff == '\r')
{
/*LINE-CHANGE*/
x++;
y=0;
output(x,y);
}
else if(buff == 27)
{
/*save*/
int i,j;
for(i=0;i<=x;i++)
{
for(j=0;j<y;j++)
{
fprintf(fp,"%c",data[i][j]);
}
}
fclose(fp);
break;
}
else
{
data[x][y] = buff;
y++;
output(x,y);
}
}
system("pause");
return 0;
}
y没有声明类型,应该是int output(int x,int y)
y没有声明类型,应该是int output(int x,int y),函数需要返回值,代码修改如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char data[10001][10001];
int output(int x,int y)
{
int i,j;
for(i=0;i<=x;i++)
{
for(j=0;j<y;j++)
{
printf("%c",data[x][y]);
}
}
return 0;
}
int main()
{
FILE *fp = fopen("test.txt","w+");
/*the FILE I/O starting x=line y=list*/
int x=0,y=1;//x指向栈顶的下一个元素
char buff;
for(;;)
{
buff = getchar();
/*meaning-changed char or normal-char*/
if(buff == '\b' && (x>0||y>1))
{
/*backspace or backline*/
if(y>0)
{
data[x][--y] = 0;
}
else
{
x--;
y = strlen(data[x]);
output(x,y);
}
}
else if(buff == '\r')
{
/*LINE-CHANGE*/
x++;
y=0;
output(x,y);
}
else if(buff == 27)
{
/*save*/
int i,j;
for(i=0;i<=x;i++)
{
for(j=0;j<y;j++)
{
fprintf(fp,"%c",data[i][j]);
}
}
fclose(fp);
break;
}
else
{
data[x][y] = buff;
y++;
output(x,y);
}
}
system("pause");
return 0;
}