SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #define MAXR 50
  3. void leggiMatrice(int M[MAXR][MAXR], int *nr, int *nc){
  4.    FILE *fp;
  5.    int i=0, j=0, k=0, p=0, rmax=0, cmax=0;
  6.    char s[MAXR];
  7.    fp=fopen("mappa.txt", "r");
  8.    for(i=0; i<MAXR && k!=EOF; i++){
  9.        k=fscanf(fp, "%s", s);
  10.        for(j=0; j<MAXR && ((sscanf(s, "%d", &M[i][j]))!=EOF); j++) {
  11.            if(j>cmax){
  12.                cmax=j;
  13.            }
  14.        }
  15.        if(i>rmax){
  16.            rmax=i;
  17.        }
  18.    }
  19.    *nr=rmax;
  20.    *nc=cmax;
  21.    fclose(fp);
  22.  
  23. }
  24. int main() {
  25.     int M[MAXR][MAXR], nr=0, nc=0;
  26.     leggiMatrice(M, &nr, &nc);
  27.     printf("%d %d", nr, nc);
  28.     return 0;
  29. }
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