View difference between Paste ID: MgQV5jnJ and p3Li24jr
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <string.h>
3
#include <stdlib.h>
4
5-
#define SIMV "!@#$%^&*():\";'/.,<>?\\0123456789\n\r- "
5+
#define SIMV "!@#$%^&*():\";'/.,<>[]{}|`~?\\0123456789\n\r- "
6
7
struct slova {
8-
	char word[40];
8+
        char word[40];
9
};
10
11
int conc(slova*, char*, int);
12
char caseup(char);
13
void swap(slova *&, int, int);
14
void sort(slova *&, int);
15
void print(slova *, int);
16
17
int main() {
18-
	slova *slovar;
18+
        slova *slovar;
19-
	FILE *h; int fsize,i,n=0;
19+
        FILE *h; int fsize,i,n=0;
20-
	char *str, *pch;
20+
        char *str, *pch;
21
22-
	//open-file
22+
        //open-file
23-
	h=fopen("a.txt","r");
23+
        h=fopen("D:\\a.txt","r");
24-
	if(!h) return 0;
24+
        if(!h) return 0;
25
26-
	//file-size
26+
        //file-size
27-
	fseek(h,0,SEEK_END);
27+
        fseek(h,0,SEEK_END);
28-
	fsize=ftell(h);
28+
        fsize=ftell(h);
29-
	rewind(h);
29+
        rewind(h);
30
31-
	//read-file
31+
        //read-file
32-
	str=(char*)malloc(sizeof(char)*fsize);
32+
        str=(char*)malloc(sizeof(char)*fsize);
33-
	fread(str,sizeof(char),fsize,h);
33+
        fread(str,sizeof(char),fsize,h);
34-
	str[fsize]='\0';
34+
        str[fsize]='\0';
35
36-
	//close-file
36+
        //print-str
37-
	fclose(h);
37+
        puts(str);
38
39-
	//case-up
39+
        //close-file
40-
	for(i=0;i<fsize;i++) str[i]=caseup(str[i]);
40+
        fclose(h);
41
42-
	//del-symb + create-slovar
42+
        //case-up
43-
	pch=strtok(str,SIMV);
43+
        for(i=0;i<fsize;i++) str[i]=caseup(str[i]);
44-
	slovar=(slova*)calloc(1,sizeof(slova));
44+
45-
	while(pch) {
45+
        //del-symb + create-slovar
46-
		if(!conc(slovar,pch,n)) { //del-conc
46+
        pch=strtok(str,SIMV);
47-
		strcpy(slovar[n++].word,pch); //slovar <- str
47+
        slovar=(slova*)calloc(1,sizeof(slova));
48-
		slovar=(slova*)realloc(slovar,(n+1)*sizeof(slova)); //slovar[+1]
48+
        while(pch) {
49-
		}
49+
                if(!conc(slovar,pch,n)) { //del-conc
50-
		pch=strtok(NULL,SIMV); //next-word
50+
                strcpy(slovar[n++].word,pch); //slovar <- str
51-
	}
51+
                slovar=(slova*)realloc(slovar,(n+1)*sizeof(slova)); //slovar[+1]
52
                }
53-
	//print
53+
                pch=strtok(NULL,SIMV); //next-word
54-
	sort(slovar,n);
54+
                if(!pch) slovar=(slova*)realloc(slovar,(n--)*sizeof(slova)); //slovar[+1]
55-
	print(slovar,n);
55+
        }
56
57-
	return 0;
57+
        //print
58
        sort(slovar,n);
59
        print(slovar,n);
60
61-
	for(int i=0;i<n;i++) if(strcmp(slovar[i].word,pch)==0) return 1;
61+
        return 0;
62-
	return 0;
62+
63
64
int conc(slova* slovar, char* pch, int n) {
65
        for(int i=0;i<n;i++) if(strcmp(slovar[i].word,pch)==0) return 1;
66-
	if(u<='z' && u>='a') return u-32;
66+
        return 0;
67-
	return u;
67+
68
69
char caseup(char u) {
70
        if(u<='z' && u>='a') return u-32;
71-
	slova temp;
71+
        return u;
72-
	temp=slovar[x];
72+
73-
	slovar[x]=slovar[y];
73+
74-
	slovar[y]=temp;
74+
75
        slova temp;
76
        temp=slovar[x];
77
        slovar[x]=slovar[y];
78-
	int max;
78+
        slovar[y]=temp;
79-
	for(int j=0;j<n;j++) {
79+
80-
		max=j;
80+
81-
		for(int i=j;i<n;i++) {
81+
82-
			if(slovar[max].word<slovar[i].word) max=i;
82+
        int max,i,j;
83-
		}
83+
        for(j=0;j<n-1;j++) {
84-
		swap(slovar,max,j);
84+
                max=j;
85-
	}
85+
                for(i=j;i<n;i++) {
86
                        if(strcmp(slovar[max].word,slovar[i].word)>0) max=i;
87
                }
88
                if(max!=j) swap(slovar,max,j);
89-
	for(int i=0;i<n;i++) printf("[%3d]%20s\n",i,slovar[i].word);
89+
        }
90
}
91
92
void print(slova * slovar, int n) {
93
        for(int i=0;i<n;i++) printf("[%3d]%20s\n",i+1,slovar[i].word);
94
}