Advertisement
visoft

Pregatire 12.11 Citire din fisier, linie cu linie

Nov 12th, 2020
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. // o tabela de int-uri
  4. // o tabela de tabele de int-uri
  5. // numarul de elemente din fiecare vector
  6. // numarul de vectori
  7.  
  8. typedef struct{
  9.     int numar_de_vectori; // numarul de vectori
  10.     int *lungime_individuala; // numarul de elemente din fiecare vector
  11.     int **vectori; // o tabela de tabele de int-uri
  12. }TabelMare;
  13.  
  14. #define MAX_LINE_LEN 10000
  15.  
  16. int main() {
  17.     // 3 4 2
  18.     // 10 11
  19.     // 4
  20.     TabelMare tab;
  21.     tab.numar_de_vectori = 3;
  22.     tab.lungime_individuala = (int*)calloc(sizeof(int), tab.numar_de_vectori);
  23.     tab.vectori = (int**)calloc(sizeof(int*), tab.numar_de_vectori);
  24.  
  25.     tab.lungime_individuala[0] = 3;
  26.     tab.lungime_individuala[1] = 2;
  27.     tab.lungime_individuala[2] = 1;
  28.  
  29.     for (int i = 0; i < tab.numar_de_vectori; ++i) {
  30.         tab.vectori[i] = (int*)calloc(sizeof(int), tab.lungime_individuala[i]);
  31.     }
  32.  
  33.     tab.vectori[0][0] = 3;
  34.     tab.vectori[0][1] = 4;
  35.     tab.vectori[0][2] = 2;
  36.     tab.vectori[1][0] = 10;
  37.     tab.vectori[1][1] = 11;
  38.     tab.vectori[2][0] = 4;
  39.  
  40.     FILE *f = fopen("../in.txt", "r");
  41.     if (f == NULL){
  42.         return 1;
  43.     }
  44.     int ok=1;
  45.     char*linie = (char*)calloc(sizeof(char ), MAX_LINE_LEN);
  46.     while (ok){
  47.         int rez_fgets = fgets(linie, MAX_LINE_LEN, f);
  48.         if (rez_fgets == NULL || rez_fgets == EOF){
  49.             break;
  50.         }
  51.         printf("-:%s", linie);
  52.     }
  53.  
  54.  
  55. //    for (int i = 0; i < tab.numar_de_vectori; ++i) {
  56. //        for (int j = 0; j <tab.lungime_individuala[i]; ++j) {
  57. //            printf("%d ", tab.vectori[i][j]);
  58. //        }
  59. //        printf("\n");
  60. //    }
  61.  
  62.     return 0;
  63. }
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement