Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

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