69,371
社区成员
发帖
与我相关
我的任务
分享
//所谓修改删除文件a某位置的内容,其实是读打开文件a,再将‘a中修改删除位置之前的内容+修改删除的内容+a中修改删除位置之后的内容’保存到文件b,关闭文件a,
//删除文件a,将文件b改名为与之前文件a相同的名字,仅此而已。
#include <stdio.h>
FILE *fi,*fo;
char ln[256],c;
int N,M,v;
int main() {
fi=fopen("APDL3.mac","r");
if (NULL==fi) {
printf("Can not open file APDL3.mac!\n");
return 1;
}
fo=fopen("tmp.mac","w");
if (NULL==fo) {
fclose(fi);
printf("Can not create file tmp.mac!\n");
return 2;
}
while (1) {
printf("Input N,M:");fflush(stdout);
rewind(stdin);
if (2==scanf("%d,%d",&N,&M)) break;
}
while (1) {
if (NULL==fgets(ln,256,fi)) break;
if (2==sscanf(ln,"N=%d%c",&v,&c)) {
if ('\n'==c) {
fprintf(fo,"N=%d\n",N);
continue;
}
}
if (2==sscanf(ln,"M=%d%c",&v,&c)) {
if ('\n'==c) {
fprintf(fo,"M=%d\n",M);
continue;
}
}
fprintf(fo,"%s",ln);
}
fclose(fo);
fclose(fi);
remove("APDL3.mac");
rename("tmp.mac","APDL3.mac");
return 0;
}
#include <stdio.h>
#include <string.h>
char s[256];
char *p;
int r,n,i;
int main() {
while (1) {
printf("请输入一行文字(空行结束),\"%%20\"将替换为\" \",\"你懂得\"将替换为\"XXXXXX\":\n");
fgets(s,256,stdin);
if ('\n'==s[0]) break;
p=s;
while (1) {
p=strstr(p,"%20");
if (p) {
memmove(p+1,p+3,strlen(p)-3+1);
p[0]=' ';
} else break;
}
p=s;
while (1) {
p=strstr(p,"你懂得");
if (p) {
memmove(p+6,p+6,strlen(p)-6+1);
for (i=0;i<6;i++) p[i]='X';
} else break;
}
printf("%s",s);
}
return 0;
}
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//abcdefg%20helloworld%20something.pdf
//abcdefg helloworld something.pdf
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//这是测试文字你懂得,在这个你懂的地方,就得做你懂得的事
//这是测试文字XXXXX,在这个你懂的地方,就得做XXXXX的事
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fin;
char x, y,a;
int n,N;
int i;
fin = fopen("d:\\APDL3.mac", "r");
for (i = 0; i<4; i++) fscanf(fin, "%*[^\n]%*c"); // 跳2 行
fscanf(fin, "%c %c %d", &x, &y, &n); // 读 3 个 字符
scanf("%d", &N); //输入N的值
n = N;
printf("%c %c %d\n", x, y, n); // 打出 N = ?
fclose(fin);
}