Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <limits.h>
- int is_all_alpha(char *str){
- char *s = str;
- while (isalpha(*s)){
- s++;
- }
- if (*s == '\n') {
- return 1;
- }
- return 0;
- }
- char **podstr_split(char **s, int size_arr){
- int n = 0;
- char **podstr_arr = malloc(sizeof(char*) * 5);
- char **ps = podstr_arr;
- for(char **str = s; str < s + size_arr; str++){
- if (is_all_alpha(*str)){
- *ps = malloc(sizeof(char) * (strlen(*str) + 1));
- strcpy(*ps, *str);
- ps++;
- n++;
- 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 zam_symbol(char *s, char old, char h){
- char *p = s;
- while((p = strchr(p, old))){
- *p = h;
- p++;
- }
- }
- int find_sub(char *str, char fs){
- if (strchr(str, fs)) {
- return 1;
- }
- return 0;
- }
- int main(int argc, const char * argv[]) {
- FILE *f;
- char buf[80], **p = NULL, **str = NULL, **s, **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);
- for(s = str; s < str + n; s++){
- zam_symbol(*s, '*', '#');
- puts(*s);
- free(*s);
- }
- printf("\n__________________________________\n\n");
- for(s = podstr; *s; s++){
- if(find_sub(*s, 'x'))
- puts(*s);
- free(*s);
- }
- free(podstr);
- free(str);
- fclose(f);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement