Malo sam prepravio tvoj kod. Ipak je ovo C++ forum :D
Code:
#include <iostream>
using namespace std;
#define MAX_LINE_LENGHT 2048
#define MAX_NUM_LENGTH 50
int main(int argc, char* argv[])
{
FILE* input;
FILE* output;
char temp_line[MAX_LINE_LENGHT];
char temp_string[MAX_LINE_LENGHT];
char num_buffer[MAX_NUM_LENGTH];
if(argc<3)
{
cout << "Usage: app_name.exe input_filename output_filename" << endl;
return 1;
}
if(!(input=fopen(argv[1],"r")))
{
cout << "Error opening input file " << argv[1] << endl;
return 2;
}
if(!(output=fopen(argv[2],"w")))
{
cout << "Error opening output file " << argv[2] << endl;
return 3;
}
while(!(feof(input)))
{
static unsigned long i = 0;
strcpy(temp_string,"n ");
itoa(++i,num_buffer,10);
strcat(temp_string,num_buffer);
strcat(temp_string,". ");
fgets (temp_line, MAX_LINE_LENGHT, input);
strcat(temp_string,temp_line);
fputs(temp_string,output);
}
fclose(output); fclose(input);
cout << "Done." << endl;
return 0;
}
Zanima me da li može da se optimizuje ovaj kod.
Mnogo mi je to koda.
U Perl-u je mnogo manje :)
Hvala!
[Ovu poruku je menjao Pharos dana 28.04.2006. u 02:51 GMT+1]
77 77 77 2E 65 73 6E 69 70 73 2E 63 6F 6D