include stdio include stdlib include windows include string include lo

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <locale.h>
#define N 500
int main(int argc, char *argv[])
{
setlocale(LC_ALL,"Russian");
FILE *file, *file2 ;
long int end; /* ïðèçíàê êîíöà ôàéëà */
int i=0; /* èíäåêñ ñòðîêè */
int COLVOslov=0, MAXslov=0; /* COLVOslov-ñ÷åòêèê êîë-âà ñëîâ â ñòðîêå, MAXslov-ìàêñèìàëüíîå êîë-âî ñëîâ â ñòðîêå*/
char si; /* ïîñèìâîëüíîå ñ÷èòûâàíèå èç ôàéëà */
char *pi; /* óêàçàòåëü äëÿ strtok */
char Vstr[N]="\0", MAXstr[N]="\0",strWithMaxSlov[N]="\0"; /* âðåìåííàÿ ñòðîêà, ìàêñèìàëüàÿ ñòðîêà, ñòðîêà ñ ìàêñèìàëüíûì êîë-âîì ñëîâ*/
fpos_t posN,posNMAX;
/* ïåðåìåííûå äëÿ îòêðûòèÿ ôàéëà ÷åðåç ïàðàìåòðû ô-è main() */
int a=1; /* èíäåêñ äëÿ àðãóìåíòà argv ô-è main() */
char namefH[100]={},namefZ[100]={}; /* namefH-ôàéë ÷òåíèÿ, namefZ-ôàéë çàïèñè */
/* ðîçîâàÿ ìèëîòà */
HANDLE consoleOutput;
consoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consoleOutput, 1 | FOREGROUND_RED | FOREGROUND_INTENSITY);
/* ïðîâåðêà êîë-âà ïåðåäàííûõ ïàðàìåòðîâ */
if(argc==1)
{
printf("Ââåäèòå èìÿ ôàéëà äëÿ îáðàáîòêè\n");
scanf("%s", namefH);
printf("Ââåäèòå èìÿ âûõîäíîãî ôàéëà\n");
scanf("%s", namefZ);
}
if(argc==2)
{
strcpy(namefH,argv[1]);
printf("Ââåäèòå èìÿ âûõîäíîãî ôàéëà\n");
scanf("%s", namefZ);
}
if(argc==3)
{
strcpy(namefH,argv[1]);
strcpy(namefZ,argv[2]);
}
puts(namefZ);
puts(namefH);
/* ïðîâåðêà îòêðûòèÿ ôàéëà */
if((file=fopen(namefH,"r+"))== NULL)
{
printf("Íå óäàëîñü îòêðûòü %s\n", namefH);
system("PAUSE");
return 1;
}
if((file2=fopen(namefZ,"w+")) == NULL)
{
printf("Íå óäàëîñü îòêðûòü %s\n", namefZ);
system("PAUSE");
return 1;
}
fseek(file , 0, SEEK_END );
end = ftell(file);
fseek(file , 0, SEEK_SET );
fgetpos(file, &posN);
while( ftell(file)!=end )
{
si=fgetc(file);
if((si!='.') && (ftell(file)!=end))
{
if(si!='\n')
{
Vstr[i]=si;
i++;
}
else
{
Vstr[i]=' ';
i++;
}
}
else
{
Vstr[i]='\0';
i=0;
if(strlen(Vstr)>strlen(MAXstr))
strcpy(MAXstr,Vstr);
pi=strtok(Vstr," ,/|\()");
while(pi)
{
COLVOslov++;
pi=strtok(NULL," ,/|\()");
}
if(COLVOslov>MAXslov)
{
MAXslov=COLVOslov;
posNMAX=posN;
}
fgetpos(file, &posN);
COLVOslov=0;
}
}
i=0;
fsetpos(file,&posNMAX);
while((si=getc(file))!='.')
{
if(si!='\n')
{strWithMaxSlov[i]=si;
i++;
}
}
if(file2 != NULL)
{
fprintf(file2, "Ñàìàÿ äëèííàÿ ñòðîêà: \n %s\n", MAXstr);
fprintf(file2, "Ìàêñèìàëüíîå êîëè÷åñòâî ñëîâ: \n %s\n",strWithMaxSlov);
printf("èíôîðìàöèÿ â ôàéë %s çàïèñàíà óñïåøíî\n", namefZ);
}
fclose(file);
fclose(file2);
system("PAUSE");
return 0;
}