file cutter :\

Pages: 12
NOW IT ONLY CREATES 5 FILE BUT ALL THE 4 FILES STILL HAS ONLY 1 CHARACTER ONTO IT EXCEPT EXTRA WHICH HAS THE LAST PART OF THE FILE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
for( int j=0;j<n-1;++j)
                {
	     {
            for(int t=0;t<25;t++)
           {
          i[t]=randgen();
            }
             ofstream fcs;
             fcs.open(i,ios::app);
       for (int flag = 0; flag != no; ++flag)
             
             fc>>letter;
             fcs<<letter;
              c='\0';
             
          }
        memset(i,'\0',21);
      }tell=fc.tellg();
   fc.seekg(tell);
while(!fc.eof())
{
ofstream fx;
fx.open("extra",ios::app|ios::binary);
fx.seekp(0);
fc>>letter;
fx<<letter;
}
fc.close();
cout<<"complete";


I SPENT THE WHOLE DAY PONDERING OVER HE ISSUE AND CREATED THE CODE.the console screen is showing out put as expecyed also.the program seems to be skipping line 71-73!.IT MAKES 100 FILES ALL RIGHT BUT ALL FILES IT MAKES IS EMPTY HERE IS MY CODE.....IF THERE IS SOMEONE OUT THERE PLEASE HELP ME...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<fstream>
#include<ctime>
#include<cstdlib>
#include<string.h>
static const char alphanum[] =
"0123456789"
"!@#$%^&"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

int stringLength = sizeof(alphanum) - 1;
streampos filesize(const char *filename)
   {
     ifstream f(filename, ios::in|ios::ate);
     streampos size = f.tellg();
    f.close();
    return size;
  }



char genRandom()  // Random string generator function.
  {

    return alphanum[rand() % stringLength];
  }

char randgen()
  {
    
    char a;
    for(int z=0; z < 21; z++)
    {
	a=genRandom();

    }
    return a;

 }
  int main()
     {
     
     srand(time(0));
     char ah[21];
     int flag=0;
     double n;
     char chara[50],i[21],letter;
     cout<<"enter file name.extension(if any):";
    cin. gets(chara,21,'\0');
     double c;
     c=filesize(chara);
     cout<<"\nenter number of files you want to cut it into:";
     cin>>n;
     int no=c/n;
     cout<<"\neach file would have "<<no<<" characters\n";
     cout<<n<<"+1 files will be created(if necessary)\n";
     fstream fc;
     fc.open(chara,ios::in|ios::app|ios::binary);
     double tell;
     fc.seekg(0);
     for( int j=0;j<n;++j)
		{
	     for(int t=0;t<25;t++)
			  {
			     i[t]=randgen();
			  }
		  ofstream fcs;
		  fcs.open(i,ios::app|ios::binary);
		  for (int flag = 0; flag != no; ++flag)
			{
			    fc.get(letter);
			    fcs.put(letter);
			    letter='\0';


			}
		     cout<<"\tfile "<<i<<"created ";
		    memset(i,'\0',21);
	        }tell=fc.tellg();
   fc.seekg(tell);
   while(!fc.eof())
	    {
	      ofstream fx;
	      fx.open("extra",ios::app|ios::binary);
	      fx.seekp(0);
	      fc.get(letter);
	      fx.put(letter);
	     }
    fc.close();

   cout<<"\n+--------------------------------------------------------------+\n";
   cout<<"\tprocess complete                                    |\n";
  cout<<"+---------------------------------------------------------------+";
   return 0;
   }




thanks for your time and replys
Last edited on
You are still accessing outside the bounds of your array, i. Crappy name, that, by the way.
what do you mean accessing it outside of array i could you please explain
what do you mean accessing it outside of array i could you please explain

I'm pretty sure it's already been explained, but valid indices for i which is declared thusly: char chara[50],i[21],letter; are 0 to 20. In the loop that spans lines 63 to 66, you are using indices 0 to 24. Indices 21 to 24 are outside the bounds of your array. As mentioned previously upthread, you are also not NUL terminating the c-string that you generate in the same loop.
Topic archived. No new replies allowed.
Pages: 12