Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<time.h>
- #include<fstream>
- #include<string>
- using namespace std;
- int* generujN(int N)
- {
- int* tmp;
- int i;
- srand(time(NULL));
- if (N<1)
- return 0;
- tmp=new int[N];
- for(i=0;i<N;i++)
- tmp[i]=rand()%11;
- return tmp;
- }
- int liczR(char name[]){
- ifstream p;
- string tmp;
- int i=0;
- p.open(name);
- while(p.good())
- {
- getline(p,tmp);
- i++;
- }
- p.close();
- return i-1;
- }
- int liczC(char name[]){
- ifstream p;
- char c;
- int i=0,tmp;
- p.open(name);
- while(p.good())
- {
- p >> tmp;
- p.get(c);
- i++;
- if(c=='\n')break;
- }
- p.close();
- return i;
- }
- int** generuj(int R, int C){
- int **tmp;
- tmp = new int *[R];
- for (int i = 0; i < R; i++)
- tmp[i] = new int [C];
- return tmp;
- }
- int** czytaj(char name[], int *R, int *C){
- int **tmp;
- ifstream p;
- *R=liczR(name);
- *C=liczC(name);
- tmp=generuj(*R,*C);
- p.open(name);
- for(int i=0; i<*R;i++){
- for(int j=0; j<*C; j++){
- p>>tmp[i][j];
- p.get();
- }
- }
- p.close();
- return tmp;
- }
- int main()
- {
- int *tab;
- int i,n,j;
- int **tab1, R,C;
- char fileO[]={"linia.csv"};
- tab1 = czytaj(fileO,&R,&C);
- ifstream inputFile;
- string nazwapliku;
- cout<<"Podaj nazwe pliku: ";
- getline(cin, nazwapliku);
- inputFile.open(nazwapliku.c_str());
- nazwapliku.erase(nazwapliku.find_last_of('.'),string::npos);
- nazwapliku=nazwapliku+"_nowu.csv";
- ofstream file(nazwapliku.c_str());
- if(inputFile.fail()){
- cerr<<"Blad otwarcia pliku"<<endl;
- return(1);
- }
- tab = generujN(R+2);
- for (i=0; i<R+2; ++i)
- cout<<tab[i]<< " ";
- cout<<endl;
- delete [] tab;
- for( i=0; i<R; i++){
- for( j=0; j<C; j++){
- tab1[i][j]=tab1[i][j]+tab[i+2];
- cout << tab1[i][j]<<";";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement