| | |
C++ File Generator
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
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 ! =)
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 ! =)
c++ Syntax (Toggle Plain Text)
#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; } } } } }
Last edited by Eyies; Mar 30th, 2007 at 12:11 am.
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi all, I have managed to find a IntToString algorithm and I THINK its working, however the files are not generating. Sigh. If you could look over my code that would be great!
C++ Syntax (Toggle Plain Text)
#include <string> #include <cstring> #include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include <string> using namespace std; string IntToString(unsigned int x) { static const int Radix = 10; static const int MaxDigits = 20; if (0 == x) return "0"; char Tmp[MaxDigits + 1]; char* Cur = Tmp + MaxDigits; *Cur = '\0'; while (x && (Cur > Tmp)) { --Cur; *Cur = (x%Radix) + '0'; x /= Radix; } return Cur; } 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"){ cout<<"sup"<<endl; //begin loop string classSize,increm; for (int i=0;i<3;i++){ cout<<i<<endl; 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()); cout<<dest<<endl; cout<<increm<<endl; 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+1)*incremTEMP; increm=IntToString(incremTEMP); } } } } }
Last edited by Eyies; Mar 30th, 2007 at 1:03 am.
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
lol never mind. I figured it all out, now to implement different flags, sorry for the spam guys. =)
c++ Syntax (Toggle Plain Text)
#include <string> #include <cstring> #include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include <string> using namespace std; string IntToString(unsigned int x) { static const int Radix = 10; static const int MaxDigits = 20; if (0 == x) return "0"; char Tmp[MaxDigits + 1]; char* Cur = Tmp + MaxDigits; *Cur = '\0'; while (x && (Cur > Tmp)) { --Cur; *Cur = (x%Radix) + '0'; x /= Radix; } return Cur; } 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"){ cout<<"sup"<<endl; //begin loop string classSize,increm; for (int i=0;i<3;i++){ cout<<i<<endl; 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+"_"+IntToString(incremTEMP); 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+atoi(increm.c_str()); } } } } }
![]() |
Similar Threads
- Cygwin file generator (C)
- Header file Generator (C)
- File generator/tracking (IT Professionals' Lounge)
Other Threads in the C++ Forum
- Previous Thread: struct functions - lost a wee bit (i hope) in calling the functions
- Next Thread: Why NOT void main()
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





