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

Re: C++ File Generator

  #3  
Mar 30th, 2007
lol never mind. I figured it all out, now to implement different flags, sorry for the spam guys. =)
  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. string IntToString(unsigned int x)
  13. {
  14. static const int Radix = 10;
  15. static const int MaxDigits = 20;
  16.  
  17. if (0 == x) return "0";
  18.  
  19. char Tmp[MaxDigits + 1];
  20. char* Cur = Tmp + MaxDigits;
  21. *Cur = '\0';
  22. while (x && (Cur > Tmp))
  23. {
  24. --Cur;
  25. *Cur = (x%Radix) + '0';
  26. x /= Radix;
  27. }
  28. return Cur;
  29. }
  30.  
  31. int main(int argcount, char* args[]){
  32. int number_of_arguments = argcount-1;
  33.  
  34. for (int i=1;i<=number_of_arguments;i++){
  35. string argTemp = args[i];
  36.  
  37. if (argTemp == "-d"){
  38. cout<<"sup"<<endl;
  39. //begin loop
  40. string classSize,increm;
  41. for (int i=0;i<3;i++){
  42. cout<<i<<endl;
  43. if (i==0){classSize="102";increm="100";}
  44. if (i==1){classSize="1024";increm="1000";}
  45. if (i==2){classSize="10240";increm="10000";}
  46. if (i==3){classSize="102400";increm="100000";}
  47.  
  48.  
  49. int incremTEMP=atoi(increm.c_str());
  50. int classSizeTEMP=atoi(classSize.c_str());
  51. for (int j=0;j<9;j++){
  52. string dest=args[2];
  53. dest=dest+"/class"+classSize+"_"+IntToString(incremTEMP);
  54. ofstream myfile (dest.c_str());
  55. if (!myfile.is_open()) { //check validity of file
  56. cerr << "Error: cannot open the file " << dest << endl;
  57. exit (-1);
  58. }else{
  59. for (int k=0;k<(classSizeTEMP+incremTEMP)/2;k++){
  60. myfile<<"LO";
  61. }
  62. }
  63. myfile.close();
  64. incremTEMP=incremTEMP+atoi(increm.c_str());
  65. }
  66. }
  67. }
  68. }
  69. }
  70.  
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:09 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC