Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define NR_ROWS 10
- #define NR_COLUMNS 10
- #define WORD_L 32
- typedef char WORD [WORD_L];
- int main(){
- //Declares and initializes variables
- int row_count, col_count;
- WORD str_array[NR_ROWS][NR_COLUMNS];
- char c;
- //Defines and open text files
- FILE *input_file, *output_file;
- input_file = fopen("input7_3.txt", "r");
- if(input_file == NULL){
- printf("The input file does not exist or cannot be opened.\n");
- exit(1);
- }
- output_file = fopen("output7_3.txt", "w");
- if(input_file == NULL){
- printf("The output file cannot be created or cannot be opened.\n");
- exit(1);
- }
- //=============================
- //Inroduces the program
- printf("\n");
- //=============================
- row_count = 0;
- col_count = 0;
- while (fscanf (input_file, "%s", str_array[row_count][col_count]) != EOF) {
- // removes the space after the first word of the line
- c = fgetc (input_file);
- col_count++;
- // read all the remaining words of the current line
- while (c != '\n' && c != EOF) {
- fscanf (input_file, "%s", str_array[row_count][col_count]);
- //printf("%d, %d: %s\n", row_count, col_count, str_array[row_count][col_count]);
- c = fgetc (input_file);
- //printf("%c\n", c);
- col_count++;
- }
- row_count++;
- col_count = 0;
- } // while
- // for(row_count = 0; row_count < 10; row_count++){
- // for(col_count = 0; col_count < 10; col_count++){
- // printf("%s\n", str_array[row_count][col_count]);
- // }
- // }
- //======================================
- //Closes the files
- fclose(input_file);
- fclose(output_file);
- return 0;// Exits the program
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement