1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
#define MAX 300
void concatena1(char *pun, char s[][MAX], int *i, char *c){
if(strlen(pun)){
pun=strchr(s[*i],'\t');
strncat(c,s[*i],((long)s-(long)pun));
concatena1(pun,s,i,c);
}
else{
strcat(c,s[*i]);
return;
}
}
void concatena(char s[][MAX], char *c,int *righe){
for(int i=0;i<*righe;++i){
char *pun;
concatena1(pun,s,&i,c);
}
*righe--;
}
int main(int argc,char *argv[]){
ifstream entrata;
ofstream uscita;
char s[MAX][MAX];
entrata.open(argv[1],ios::in);
if(entrata.fail()){
cerr << "Il file " << argv[1] << " non esiste\n";
exit(0);
}
int j=0;
int lunghezza=0;
do{
entrata.getline(s[j++],MAX-1);
lunghezza=+strlen(s[j-1]);
}
while(entrata.eof());
entrata.close();
char c[lunghezza];
concatena(s,c,&j);
uscita.open(argv[2],ios::out);
uscita<<c;
uscita.close();
return 0;
}
|