Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define BUFFER 1024
- struct fill
- {
- char *string;
- struct fill *next_string
- }*start = NULL,
- *list;
- void error(int num)
- {
- switch(num)
- {
- case 1:
- printf("Not enough space in buffer\n");
- break;
- case 2:
- printf ("Memory allocation error\n");
- break;
- }
- exit(1);
- }
- void input(char c,char *buf)
- {
- int i=0;
- while ((c = getchar()) != EOF)
- {
- if (((c == ' ') || (c == '\n')) && (i != 0))
- {
- buf[i]='\0';
- break;
- }
- else
- {
- if ( ( ( c >= 'a' && c <= 'z' ) ) ||
- ( c >= 'A' && c <= 'Z' ) )
- {
- buf[i]=c;
- i++;
- }
- }
- }
- buf[i]='\0';
- }
- char *creat_din(char *mas,char *buf)
- {
- int n = strlen(buf);
- mas = (char *)malloc((n+1)*sizeof(char));
- if (mas == NULL) error(2);
- strcpy(mas, buf);
- return mas;
- }
- struct fill *use_struct (struct fill *list,char *mas)
- {
- list = (struct fill*)malloc(sizeof(struct fill));
- if (list == NULL) error(2);
- list->string = mas;
- list->next_string = start;
- start = list;
- printf("%s\n",list->string);
- return list;
- }
- void entry(struct fill *start, FILE *mine)
- {
- while (start!=NULL)
- {
- fputs(start->string, mine);
- fputc('\n', mine);
- free(start);
- start=start->next_string;
- }
- }
- int main(/*int argc, char *argv[]*/)
- {
- FILE *mine;
- char c, buf[BUFFER];
- char *mas;
- struct fill *rofl;
- // if (argc == 2)
- // {
- // printf("Invalid input data, try again");
- // exit(2);
- // }
- // if ((mine = fopen(argv[1], "w")) == NULL)
- // perror(argv[1]);
- printf("Enter strings\n");
- do
- {
- input(c,buf);
- if (buf[0] != '\0')
- {
- mas = creat_din(mas,buf);
- list = use_struct(list, mas);
- }
- }
- while (*buf != '\0');
- for (rofl = start ;rofl!=NULL;rofl=rofl->next_string)
- {
- printf("string %s\n",rofl->string);
- }
- //entry(start, mine);
- //fclose(mine);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement