Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 8th, 2020 171 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define NR_ROWS 10
  6. #define NR_COLUMNS 10
  7.  
  8. #define WORD_L  32
  9.  
  10. int main(){
  11.    
  12.     //Declares and initializes variables
  13.     int row_count, col_count;
  14.     char str_array[NR_ROWS][NR_COLUMNS] = {'\0'};
  15.     char c;
  16.     int terminate_flag = 0, pos_m, pos_n, numb_of_lines = 0;
  17.     char str_temp[32];
  18.    
  19.     //Defines and open text files
  20.     FILE *input_file, *output_file;
  21.     input_file = fopen("input7_3.txt", "r");
  22.     if(input_file == NULL){
  23.         printf("The input file does not exist or cannot be opened.\n");
  24.         exit(1);
  25.     }
  26.    
  27.     output_file = fopen("output7_3.txt", "w");
  28.     if(input_file == NULL){
  29.         printf("The output file cannot be created or cannot be opened.\n");
  30.         exit(1);
  31.     }
  32.    
  33.     //=============================
  34.    
  35.     //Inroduces the program
  36.     printf("\n");
  37.    
  38.     //=============================
  39.    
  40.     printf("Note: The counting is starting from 0 like an array.\n");
  41.    
  42.     row_count = 0;
  43.     col_count = 0;
  44.     while (1) {
  45.  
  46.         // read all the remaining words of the current line
  47.         fscanf (input_file, "%s", &str_temp);
  48.         strcat(str_array[row_count], str_temp);
  49.         printf("%d: %s\n", row_count, str_array[row_count][col_count]);
  50.         c = fgetc (input_file);
  51.         printf("%c\n", c);
  52.        
  53.         if(c == '\n'){
  54.             row_count++;
  55.             numb_of_lines++;
  56.         }
  57.         if(c == EOF){
  58.             break;
  59.         }
  60.         //col_count = 0;
  61.     } // while
  62.     numb_of_lines--;
  63.    
  64.     for(row_count = 0; row_count < numb_of_lines; row_count++){
  65.         printf("Line %d: ", row_count);
  66.         col_count = 0;
  67.         while(str_array[row_count][col_count] != '\0'){
  68.             printf("%d  ", col_count);
  69.             printf("%s ", str_array[row_count][col_count]);
  70.             col_count++;
  71.         }
  72. //      col_count = 0;
  73.         printf("\n");
  74.     }
  75. // 
  76. //  printf("I - Inserts a new line.\n");
  77. //  printf("D - deletes all lines between m and n\n");
  78. //  printf("R - Replaces 2 lines between m and n\n");
  79. //  printf("E - Terminates editing\n");
  80. // 
  81. //  while(1){
  82. //      printf("Please give an input of I, D, R, or E: ");
  83. //      scanf("%c", &c);
  84. //      fflush(stdin);
  85. //      switch(c){
  86. //          case'i':
  87. //          case'I':{
  88. //              printf("Input the line m that the line will be inserted after: ");
  89. //              scanf("%d", &pos_m);
  90. //              fflush(stdin);
  91. //              row_count = numb_of_lines;
  92. //              while(str_array[row_count][col_count]){
  93. //                 
  94. //              }
  95. //              break;
  96. //          }
  97. //          case'd':
  98. //          case'D':{
  99. //              printf("Input the line m: ");
  100. //              scanf("%d", &pos_m);
  101. //              fflush(stdin);
  102. //              printf("Input the line n: ");
  103. //              scanf("%d", &pos_n);
  104. //              fflush(stdin);
  105. //             
  106. //              break;
  107. //          }
  108. //          case'r':
  109. //          case'R':{
  110. //              printf("Input the line m: ");
  111. //              scanf("%d", &pos_m);
  112. //              fflush(stdin);
  113. //              printf("Input the line n: ");
  114. //              scanf("%d", &pos_n);
  115. //              fflush(stdin);
  116. //             
  117. //              break;
  118. //          }
  119. //          case'e':
  120. //          case'E':{
  121. //              terminate_flag = 1;
  122. //              break;
  123. //          }
  124. //          default: printf("Invalid input.\n");
  125. //      }
  126. //     
  127. //      for(row_count = 0; row_count < numb_of_lines; row_count++){
  128. //          printf("Line %d: ", row_count);
  129. //          for(col_count = 0; col_count < 10; col_count++){
  130. //              printf("%s ", str_array[row_count][col_count]);
  131. //          }
  132. //          printf("\n");
  133. //      }
  134. //     
  135. //      if(terminate_flag == 1){
  136. //          printf("Loop terminated.\n");
  137. //          break;
  138. //      }
  139. //  }
  140.  
  141.    
  142.    
  143.     //======================================
  144.    
  145.     //Closes the files
  146.     fclose(input_file);
  147.     fclose(output_file);
  148.    
  149.     return 0;// Exits the program
  150. }
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