Hey all, I'm new to this forum, first post.. so please excuse me (also excuse the perhaps not so eloquent style, it is still in preliminary!) =). I'm writing a short piece of code in compliance with a webserver I've been programming with a group. This code is to auto generate an assorted sizes of files (which will later be used to test latency timings and average GET request timings) starting from size Class 0 which are files less
than 1KB, class 1 files are less than 10K, class 2 files are less than 100K and class 3 files
are less than 1MB. It should auto-populates the specified directory with the four
classes of files. There will be 9 files per class. Files in class 0 are in increments of
0.1KB (starting at 102 bytes) while class 1, class 2 and class 3 are in increments of 1KB. Syntax to use the code is HTMLGenerator -d <directory>. Output files should have the form of class<classsize#>_<increment>.
My greatest problem is that our school's compiler is old and does not contain <sstream> hence making my INT to String conversion difficult. Currently the code seg faults, likely due to improper usage of the *buffer. Any questions regarding the code I will promptly reply as I'm still working away. Any suggestions on how I can get this done? Thank you all greatly for your time and help ! =)
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argcount, char* args[]){
int number_of_arguments = argcount-1;
for (int i=1;i<=number_of_arguments;i++){
string argTemp = args[i];
if (argTemp == "-d"){
//begin loop
string classSize,increm;
for (int i=0;i<1;i++){
if (i==0){classSize="102";increm="100";}
if (i==1){classSize="1024";increm="1000";}
if (i==2){classSize="10240";increm="10000";}
if (i==3){classSize="102400";increm="100000";}
int incremTEMP=atoi(increm.c_str());
int classSizeTEMP=atoi(classSize.c_str());
for (int j=0;j<9;j++){
string dest=args[2];
dest=dest+"/class"+classSize+"_"+increm;
ofstream myfile (dest.c_str());
if (!myfile.is_open()) { //check validity of file
cerr << "Error: cannot open the file " << dest << endl;
exit (-1);
}else{
for (int k=0;k<(classSizeTEMP+incremTEMP)/2;k++){
myfile<<"LO";
}
}
myfile.close();
incremTEMP=incremTEMP+j*incremTEMP;
//problems here (i'm really not sure i'm using
//sprintf correctly at all, let alone storing the
// data in buffer back into increm
char *buffer[100];
sprintf(buffer[100], "%d",incremTEMP);
for (int i=1;i<=100;i++) increm+=buffer[i];
delete *buffer;
}
}
}
}
}