高手帮忙
#include <stdio.h>#define WIDTH 80
#define LEFT 0
#define CENTER 1
#define RIGHT 2
void fillchar(FILE *fp, char c, int m);
void flushline(FILE *fp, char *bp, int l, int m);
int main(int argc, char *argv[])
{
FILE *fpi, *fpo;
int meta = 0;
int mode = LEFT;
char ch;
if(argc!=3) {
fprintf(stderr, "Illegal number of argument.\n");
return(-1);
}
if((fpi=..........)==NULL) {
fprintf(stderr, "Can't open input file <%s>.\n", argv[1]);
return(-1);
}
if((fpo=..........)==NULL) {
fprintf(stderr, "Can't open output file <%s>.\n", argv[2]);
return(-1);
}
while((ch=fgetc(fpi))!=EOF) {
if(meta==1) {
switch(ch) {
case 'c': mode=CENTER; break;
case 'r': mode=RIGHT; break;
case 'l': mode=LEFT; break;
default: fillchar(fpo,'/', mode);
fillchar(fpo,ch, mode);
break;
}
meta=0;
} else if( ch == '/' ) {
meta=1;
} else {
fillchar(fpo,ch, mode);
}
}
fillchar(..........);
fclose(fpi);
fclose(fpo);
return (0);
}
void fillchar(FILE *fp, char c, int m)
{
static int length=0;
static char buf[WIDTH+1];
if((length==........) && ( c!='\n')) {
flushline(fp, buf, length, m);
length=0;
}
if(..........) {
flushline(fp, buf, length, m);
length=....;
} else {
buf[.......]=c;
}
}
void flushline(FILE *fp, char *bp, int l, int m)
{
*(bp+l) ='\0';
fprintf(fp, "%*s%s\n", m*(WIDTH-l)/2, "", bp);
........的部分应该添什么
----------------解决方案--------------------------------------------------------
这哪的练习题 又发到论坛上了吧 ?
----------------解决方案--------------------------------------------------------
回复 2# 的帖子
我现在在上编程课 上面的问题 ----------------解决方案--------------------------------------------------------
前两个应该是:
1)fopen(filename,"w")
2)fopen(filename,"r")
以后的,看不太明白都忘记了,查查书吧,上面关于文件的写入有
----------------解决方案--------------------------------------------------------