Option Base 1 Dim a() As String Dim b() As Variant
Private Sub Form_click() Open "e:\in.txt" For Output As #1 k$ = InputBox("请输入字符串") n = Len(k$) ReDim a(n) As String Static b(1 To 10) As String For i = 1 To n a(i) = Mid$(k$, i, 1) Next i For i = 1 To n Print Tab(1 * i); a(i); Next i i = 1: j = 1: u = 1 While j < n
If a(j) = " " Then b(u) = Mid$(k$, i, j - i) i = j + 1 j = i u = u + 1 Else j = j + 1 End If Wend b(u) = Mid$(k$, i, j + 1) c$ = InputBox("请输入字符串") Print For i = 1 To u If b(i) <> c$ Then Print #1, b(i); Spc(3); End If Next i Close #1 End Sub 我用vb写的运行通过了,你改成c语言代码就行了
/* 将一个文件的内容复制到另一个文件,并排除"the"单词 */
#include <stdio.h> #include <stdlib.h> #include <string.h>
void process_file();
void process_file() { FILE *fp_read; FILE *fp_write; char ch; char temp[20]; int ip; ip=0; if((fp_read=fopen("read.txt","r"))==NULL) { printf("can not open the file!\n"); exit(1); } if((fp_write=fopen("write.txt","w"))==NULL) { printf("can not open the file!\n"); exit(1); } while((ch=fgetc(fp_read))!=EOF) { if(ch!=' '&&ch!='\n'&&ch!='\b') temp[ip++]=ch; else { temp[ip]='\0'; if(strcmp(temp,"the")!=0) fputs(temp,fp_write); ip=0; fputc(ch,fp_write); } } if(ip>0) { temp[ip]='\0'; fputs(temp,fp_write); } }
int main() { process_file(); }