daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int readfile_n(FILE *file) {
  4.     char a = 0;
  5.     int n = 0;
  6.     do
  7.     {
  8.         fscanf_s(file, "%c", &a);
  9.         n++;
  10.     } while (a != "0");
  11.     return n;
  12. }
  13.  
  14. char* fcounter(FILE* file) {
  15.     int* counter = (int*)malloc(readfile_n(file) * sizeof(char));
  16.     for (int i = 0; i < readfile_n(file); i++) {
  17.         fscanf_s(file, "%c", &counter[i]);
  18.     }
  19.     return counter;
  20. }
  21.  
  22. typedef struct symbols_s {
  23.     int start;
  24.     int finish;
  25. }symbols;
  26.  
  27. int start(symbols s) {
  28.     printf("From wich symbol: ");
  29.     scanf_s("%d", s.start);
  30.     return s.start;
  31. }
  32.  
  33. int finish(symbols s) {
  34.     printf("To wich symbol: ");
  35.     scanf_s("%d", s.finish);
  36.     return s.finish;
  37. }
  38.  
  39.  int lenght(symbols s, FILE* file) {
  40.      int* counter = fcounter(file);
  41.      if (finish(s) - start(s) + 1 > readfile_n(file) )
  42.      {
  43.          printf("Error");
  44.      }
  45.      int len = 0;
  46.      for (int i = start(s); i != finish(s); i++)
  47.      {
  48.          len = i;
  49.      }
  50.      return len;
  51. }
  52.  
  53.  int main() {
  54.      FILE *file;
  55.      fopen_s(&file, "C:\\Users\\refle\\Desktop\\info.txt", "r");
  56.      symbols s={};
  57.      lenght(s, file);
  58.      free(fcounter(file));
  59.      fclose(file);
  60.      getch();
  61.      return 0;
  62.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top