Advertisement
samoelxd

Aplica - lab1

Sep 1st, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. /*
  2.  * File:   main.cpp
  3.  * Author: samoel
  4.  *
  5.  * Created on 1 de septiembre de 2015, 10:52 PM
  6.  */
  7.  
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #include <iostream>
  11. #include <cstring>
  12. #include <fstream>
  13. using namespace std;
  14.  
  15. int main(int argc, char** argv) {
  16.      
  17.     ifstream input;
  18.     input.open("C://temp//data.txt",ios::in);
  19.    
  20.     if(!input){
  21.         cerr << "Error en abrir el archivo\n";
  22.     }
  23.     string matriz[20][20];
  24.     string linea;
  25.     int i= 0,j =0;
  26.     int prim = 1, tamJ = 0;
  27.     char * parte ;
  28.     while(!input.eof()){
  29.         getline(input,linea);
  30.         cout << linea << "\n";
  31.         char* line = new char[linea.length() +1 ];
  32.         strcpy(line,linea.c_str());
  33.         parte = strtok(line,",");
  34.         while(parte != NULL){
  35.             string str(parte);
  36.             matriz[i][j] = str;
  37.             j++;
  38.             parte = strtok(NULL,",");
  39.         }
  40.         if (prim){prim = 0; tamJ = j;}
  41.         i++; j = 0;
  42.     }
  43.     for(int w = 0; w < i; w++){
  44.         for(int x = 0; x < tamJ;x++){
  45.             cout << matriz[w][x] << " ";
  46.         }
  47.         cout << endl;
  48.     }
  49.     printf("todo ocs");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement