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

  #2  
Mar 30th, 2007
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!

  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){
  44. classSize="102";increm="100";}
  45. if (i==1){classSize="1024";increm="1000";}
  46. if (i==2){classSize="10240";increm="10000";}
  47. if (i==3){classSize="102400";increm="100000";}
  48.  
  49.  
  50. int incremTEMP=atoi(increm.c_str());
  51. int classSizeTEMP=atoi(classSize.c_str());
  52. for (int j=0;j<9;j++){
  53. string dest=args[2];
  54. dest=dest+"/class"+classSize+"_"+increm;
  55. ofstream myfile (dest.c_str());
  56. cout<<dest<<endl;
  57. cout<<increm<<endl;
  58. if (!myfile.is_open()) { //check validity of file
  59. cerr << "Error: cannot open the file " << dest << endl;
  60. exit (-1);
  61. }else{
  62. for (int k=0;k<(classSizeTEMP+incremTEMP)/2;k++){
  63. myfile<<"LO";
  64. }
  65. }
  66. myfile.close();
  67. incremTEMP=incremTEMP+(j+1)*incremTEMP;
  68. increm=IntToString(incremTEMP);
  69. }
  70. }
  71. }
  72. }
  73. }
Last edited by Eyies : Mar 30th, 2007 at 1:03 am.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:22 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC