Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Темирхан Мамаев on 05/12/2019.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <limits.h>
- char *min_alpha(char **s, int size_arr){
- char *p_min_alpha = NULL;
- int min_count = INT_MAX;
- for (char **ps = s; ps < s + size_arr; ps++){
- int count = 0;
- for (char *sub = *ps; sub < *ps + strlen(*ps); sub++){
- if (isalpha(*sub)) {
- count++;
- }
- }
- if (count < min_count) {
- p_min_alpha = *ps;
- min_count = count;
- }
- }
- return p_min_alpha;
- }
- char **podstr_split(char **s, int size_arr, char fs, char ls){
- int n = 0;
- char **podstr_arr = malloc(sizeof(char*) * 5);
- char **ps = podstr_arr;
- for(char **str = s; str < s + size_arr; str++){
- char *q = *str, *p = *str;
- while(isalpha(*q))
- if (strchr(q, '*')){
- *ps = malloc(sizeof(char) * (p - q));
- strncpy(*ps, (q + 1), (p - q - 1));
- *(*ps + (p - q)) = '\0';
- ps++;
- n++;
- q++;
- if (n % 5 == 0) {
- podstr_arr = realloc(podstr_arr, sizeof(char*) * (n + 5));
- ps = podstr_arr + n;
- }
- }
- }
- *(podstr_arr + n) = NULL;
- return podstr_arr;
- }
- void vstav_char(char *s, char ps, char h){
- char *p = s, *q;
- while((p = strchr(p, h))){
- q = strchr(p, '\0');
- while(q > p){
- *(q + 1) = *q;
- q--;
- }
- *(p + 1) = ps;
- p++;
- }
- }
- int main(int argc, const char * argv[]) {
- FILE *f;
- char buf[80], **p = NULL, **str = NULL, **s, *p_max, **podstr;
- int n = 0;
- if (!(f = fopen("data.txt", "rb"))) {
- printf("file don't exist");
- return 1;
- }
- else{
- while (!feof(f)) {
- str = (char**)malloc(sizeof(char*) * 5);
- p = str;
- while (!feof(f)) {
- fgets(buf, 79, f);
- *p = (char*)malloc((strlen(buf) + 1) * sizeof(char));
- strcpy(*p, buf);
- p++;
- n++;
- if (n % 5 == 0) {
- str = (char**)realloc(str, sizeof(char*) * (n + 5));
- p = str + n;
- }
- }
- }
- }
- podstr = podstr_split(str, n, '(', ')');
- p_max = min_alpha(str, n);
- puts(p_max);
- for(s = str; s < str + n; s++){
- puts(*s);
- free(*s);
- }
- printf("\n__________________________________\n\n");
- for(s = podstr; *s; s++){
- puts(*s);
- free(*s);
- }
- free(podstr);
- free(str);
- fclose(f);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement