RSS Forums RSS
Please support our C++ advertiser: Programming Forums

C++ File Generator

Join Date: Mar 2007
Posts: 3
Reputation: Eyies is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Eyies Eyies is offline Offline
Newbie Poster

C++ File Generator

  #1  
Mar 29th, 2007
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 ! =)

  1. #include <string>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. int main(int argcount, char* args[]){
  13. int number_of_arguments = argcount-1;
  14.  
  15. for (int i=1;i<=number_of_arguments;i++){
  16. string argTemp = args[i];
  17.  
  18. if (argTemp == "-d"){
  19. //begin loop
  20. string classSize,increm;
  21. for (int i=0;i<1;i++){
  22. if (i==0){classSize="102";increm="100";}
  23. if (i==1){classSize="1024";increm="1000";}
  24. if (i==2){classSize="10240";increm="10000";}
  25. if (i==3){classSize="102400";increm="100000";}
  26.  
  27.  
  28. int incremTEMP=atoi(increm.c_str());
  29. int classSizeTEMP=atoi(classSize.c_str());
  30. for (int j=0;j<9;j++){
  31. string dest=args[2];
  32. dest=dest+"/class"+classSize+"_"+increm;
  33. ofstream myfile (dest.c_str());
  34. if (!myfile.is_open()) { //check validity of file
  35. cerr << "Error: cannot open the file " << dest << endl;
  36. exit (-1);
  37. }else{
  38. for (int k=0;k<(classSizeTEMP+incremTEMP)/2;k++){
  39. myfile<<"LO";
  40. }
  41. }
  42. myfile.close();
  43. incremTEMP=incremTEMP+j*incremTEMP;
  44.  
  45. //problems here (i'm really not sure i'm using
  46. //sprintf correctly at all, let alone storing the
  47. // data in buffer back into increm
  48. char *buffer[100];
  49. sprintf(buffer[100], "%d",incremTEMP);
  50. for (int i=1;i<=100;i++) increm+=buffer[i];
  51. delete *buffer;
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
Last edited by Eyies : Mar 30th, 2007 at 12:11 am.
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:56 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC