Staminka
12-12-2013, 23:36
Нужно в файл С записать символы из файла А и файла В, которые отличаются от с 1, с 2, с 3 не больше чем на два порядковых номера. А и В создаются в процессе выполнения программы.
У меня получился вот такой код:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
char main(){
char ela,c,elb;
int ic;
char ch;
int i;
FILE*fa,fc,fb;
fa=fopen("a.txt","w+");
if (fa==NULL) {printf("ERROR!"); return 1;}
fb=fopen("b.txt","w");
if (fb==NULL) {printf("ERROR!"); return 1;}
fc=fopen("c.txt","w");
if (fc==NULL) {printf("ERROR!"); return 1;}
printf("Enter number of elements in file A: ");
scanf("%c",ela);
for(i=0;i<ela;i++){
printf("Input simvol %d", i+1);
scanf("%c",&c);
fprintf(fa,"%c ",c);
}
while ((ic = fgetc(fa)) != EOF)
{
ch = ic;
if ((ch >= c1-2 && ch <= c1+2)||(ch >= c2-2 && ch <= c2+2)||(ch >= c3-2 && ch <= c3+2))
fputc(ch, fc);
}
fc=fopen("c.txt","a");
if (fc==NULL) {printf("ERROR!"); return 1;}
printf("Enter number of elements in file B: ");
scanf("%d",&elb);
for (i=0;i<elb;i++)
{
printf("Input simvol %d ",i+1);
scanf("%c",&c);
fprintf(fb,"%c ",c);
}
while ((ic = fgetc(fb)) != EOF)
{
ch = ic;
if ((ch >= c1-2 && ch <= c1+2)||(ch >= c2-2 && ch <= c2+2)||(ch >= c3-2 && ch <= c3+2))
fputc(ch, fc);
}
getch();
fcloseall();
return 0;
}
Но в конце постоянно выплывают ошибки
У меня получился вот такой код:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
char main(){
char ela,c,elb;
int ic;
char ch;
int i;
FILE*fa,fc,fb;
fa=fopen("a.txt","w+");
if (fa==NULL) {printf("ERROR!"); return 1;}
fb=fopen("b.txt","w");
if (fb==NULL) {printf("ERROR!"); return 1;}
fc=fopen("c.txt","w");
if (fc==NULL) {printf("ERROR!"); return 1;}
printf("Enter number of elements in file A: ");
scanf("%c",ela);
for(i=0;i<ela;i++){
printf("Input simvol %d", i+1);
scanf("%c",&c);
fprintf(fa,"%c ",c);
}
while ((ic = fgetc(fa)) != EOF)
{
ch = ic;
if ((ch >= c1-2 && ch <= c1+2)||(ch >= c2-2 && ch <= c2+2)||(ch >= c3-2 && ch <= c3+2))
fputc(ch, fc);
}
fc=fopen("c.txt","a");
if (fc==NULL) {printf("ERROR!"); return 1;}
printf("Enter number of elements in file B: ");
scanf("%d",&elb);
for (i=0;i<elb;i++)
{
printf("Input simvol %d ",i+1);
scanf("%c",&c);
fprintf(fb,"%c ",c);
}
while ((ic = fgetc(fb)) != EOF)
{
ch = ic;
if ((ch >= c1-2 && ch <= c1+2)||(ch >= c2-2 && ch <= c2+2)||(ch >= c3-2 && ch <= c3+2))
fputc(ch, fc);
}
getch();
fcloseall();
return 0;
}
Но в конце постоянно выплывают ошибки