Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int readfile_n(FILE *file) {
- char a = 0;
- int n = 0;
- do
- {
- fscanf_s(file, "%c", &a);
- n++;
- } while (a != "0");
- return n;
- }
- char* fcounter(FILE* file) {
- int* counter = (int*)malloc(readfile_n(file) * sizeof(char));
- for (int i = 0; i < readfile_n(file); i++) {
- fscanf_s(file, "%c", &counter[i]);
- }
- return counter;
- }
- typedef struct symbols_s {
- int start;
- int finish;
- }symbols;
- int start(symbols s) {
- printf("From wich symbol: ");
- scanf_s("%d", s.start);
- return s.start;
- }
- int finish(symbols s) {
- printf("To wich symbol: ");
- scanf_s("%d", s.finish);
- return s.finish;
- }
- int lenght(symbols s, FILE* file) {
- int* counter = fcounter(file);
- if (finish(s) - start(s) + 1 > readfile_n(file) )
- {
- printf("Error");
- }
- int len = 0;
- for (int i = start(s); i != finish(s); i++)
- {
- len = i;
- }
- return len;
- }
- int main() {
- FILE *file;
- fopen_s(&file, "C:\\Users\\refle\\Desktop\\info.txt", "r");
- symbols s={};
- lenght(s, file);
- free(fcounter(file));
- fclose(file);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement