K
K
kolxz22020-06-22 20:33:31
C++ / C#
kolxz2, 2020-06-22 20:33:31

How to read a dynamic two-dimensional array from a C-file?

There is an example of how to count a one-dimensional array, but you need to count a two-dimensional rectangular one.

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[]){
  if (argc == 1) {
    printf("No file names");
    return 0;
  } 
  int  size;			
  FILE *OpenFile;						
  OpenFile = fopen(argv[1], "r");
  if (!OpenFile) {
    printf("Failed to open the file");
    return 0;
  } else {
    size = CountFile(OpenFile)
  }

int СountFile(FILE *OpenFile) {
  int temp, counter = 0;
  while (fscanf(OpenFile, "%d", &temp) != EOF) {
    counter++;
  }
  return counter;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2020-06-23
@CityCat4

In this code, I see how to count the elements of an array from a file. And no more. And I never understand what would prevent submitting a file with a "two-dimensional" text to the input.
What is the task?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question