Начал реализовывать, но столкнулся с проблемой как считать слово и заменить его на номер в другом массиве, а в другой его записать.
#include <stdio.h>
#include <afx.h>
#include <conio.h>
#include <ctype.h>
#include <tchar.h>
FILE *fi,*fo;
int nline=0;
int count=0;
PSTR gpPos;
void main(){
char fname[]="test2.txt";
char fname2[]="output.txt";
// printf("\nVvedite imja fhodnogo faila: ");
// scanf("%s",&fname);
if((fi=fopen(fname,"r"))==NULL)
{
printf("\nOshibka otkrytija vhodnogo faila!");
getch();
exit(0);
}
if((fo=fopen(fname,"w"))==NULL)
{
printf("\nOshibka otkrytija vhodnogo faila!");
getch();
exit(0);
}
char c;
int elem[119];
while(!feof(fi))
{
c=fgetc(fi);
count++;
if ((c=='\n')||(c==EOF))
{
nline++;
elem[nline]=count;
count=0;
}
}
char line[120]="";
char *result;
fseek (fi, 0L, SEEK_SET);
int k=0;
while (!feof(fi))
{
result=fgets(line,elem[k],fi);
gpPos=(PSTR)result;
int n=sizeof(gpPos);
for(;;)
{ gpPos++;
int j=0;
char m[20];
if isalpha(gpPos)
{
for(;;){
gpPos++;
if (gpPos==',')
break;
}
m[j]=(char)gpPos;
gpPos=PSTR(j);
}
fputc(m[j],fo);
}
k++;
}
fclose(fi);
fclose(fo);
}
Пример входного файлаНажмите для просмотра прикрепленного файла