Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / неТельминов / lab3 / LAB3-X
.CPP#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define INPUT "C:\\input.txt"
#define OUTPUT "C:\\output.txt"
#define MAX_WORD_LEN 200
#define MAX_WORDS 250
#define BUF_SIZE 1024
int main()
{
char buf[BUF_SIZE];
char list[MAX_WORDS][MAX_WORD_LEN];
int count=0, i, j, k, maxlen;
char seps[] = " ,.:;!?\t\n";
char *token;
FILE *in, *out;
clrscr();
cout << "Using " << INPUT << " as input file\n";
if ((in=fopen(INPUT,"r"))==0) {
cerr << "Can't open input file\n";
exit(1);
}
if ((out=fopen(OUTPUT,"w"))==0) {
cerr << "Can't open output file\n";
exit(1);
}
while(!feof(in)){
fgets(buf,BUF_SIZE,in);
// cout << buf;
token = strtok(buf, seps );
while( token != NULL )
{
strcpy(list[count++],token);
if(strlen(token) > maxlen) maxlen = strlen(token);
token = strtok(NULL, seps );
}
}
for(j=1;j<=maxlen;j++) {
k=0;
for(i=0;i<count;i++) {
if (strlen(list[i]) == j) { fprintf(out,"%s ",list[i]); k=1; }
}
if(k) fprintf(out,"\n");
}
cout << "Done! See " << OUTPUT << "\n";
fclose(in);
fclose(out);
return 0;
}