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>
- struct line
- {
- char *text;
- int numar;
- };
- /**
- struct line* Read(int *size, FILE* in)
- {
- struct line* list;
- list = NULL;
- char* text;
- int size_text = 0;
- int num_contor = 0;
- int new_word = 1;
- int c;
- c = fgetc(in);
- while(c!=EOF && c != (int) '\n')
- {
- size_text = 0;
- text = NULL;
- num_contor = 0;
- new_word = 1;
- (*size)++;
- //list = (struct line*)realloc(list, (*size) * sizeof(struct line));
- while(c != (int) '\n' && c!= EOF)
- {
- //printf("c");
- printf("%d", c);
- size_text++;
- //text = (char*) realloc(text, (size_text+1)*sizeof(char));
- if(new_word && isdigit((char)c))
- num_contor++;
- if(isspace((char)c))
- new_word = 1;
- c = fgetc(in);
- }
- //list[(*size)-1].text = text;
- //list[(*size)-1].numar = num_contor;
- }
- return list;
- }
- **/
- char* Read_Line(FILE *in)
- {
- //printf("%p\n", in);
- char* line;
- line = NULL;
- line = (char*) realloc(line,sizeof(char));
- int index = 0;
- int c;
- while((c = fgetc(in)) != '\n')
- {
- //printf("%c",c);
- line = (char*) realloc(line,(index+2)*sizeof(char));
- line[index] = (char)c;
- index++;
- }
- line[index] = '\0';
- return line;
- }
- int main(int argc, char* argv[])
- {
- FILE* in;
- in = fopen(argv[0], "r");
- //in = fopen("sample.txt", "r");
- //printf("%s", argv[1]);
- //printf("%p\n", in);
- if(in!=NULL)
- {
- struct line *v;
- int size = 0;
- v = NULL;
- v = (struct line*)realloc(v, sizeof(struct line));
- char *linie;
- linie = Read_Line(in);
- printf("%s", linie);
- //printf("%s", v[0].text);
- //v = Read(&size, in);
- fclose(in);
- //printf("%s", v[0].text);
- //printf("%d", size);
- }
- else
- {
- printf("Unable to open folder");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement