473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

plz help me.. this logical error is irritating...

The following code(in c++) is supposed to divide a file into 'n' different
files.

suppose i'm having a file called "input.zip".

The execution of the following code should divide "input.zip" into 'n'(user
specified) different files.

However the code currently..though makes 'n' different files... the divided
contents are stored only in the first of the 'n' files.

That is.. if "input.zip" has 25kb size, and if i want to divide it into 5
different files... then,
actually i should have 5 files with 5 kb each. but this code only gives me 1
file with 5 kb and the rest 4 files are all 0kb.

please help me.. with this problem.

void breaker()
{
long int temppos = 0,pos = 0;
int n = 0;
char choice =' ';
char file[20] = "input.zip";
char filename[2][30];
strcpy(filename[0],file);
strcpy(filename[1],filename[0]);
strcat(filename[1],"1");

ifstream infile(filename[0],ios::binary);
infile.seekg(0,ios::end);
pos=infile.tellg();

do
{
cout<<" file size in kb : "<<(float)pos/1024;
cout<<"\nenter number files to be broken into: ";
cin>>n;
temppos=pos/n;
cout<<temppos<<"\n do you want to continue?..press q to re-enter number of
files..or any other key to continue..";
cin.get(choice);

}while(choice=='q');

int ctr=0;
ofstream outfile(filename[1],ios::binary);

infile.seekg(0,ios::beg);

char byte;

infile.read(&byte,sizeof byte); //read and write functions used for working

on data the "binary" way.

char ext='1';
for(int i=0;i<n;i++)
{
ext++;

ctr=0;

while(ctr<temppos) //temppos = pos/n..in line 31
{
outfile.write(&byte, sizeof byte);
infile.read(&byte, sizeof byte);

ctr++;
}

outfile.close();
strcpy(filename[1],filename[0]);
strcat(filename[1],&ext);
outfile.open(filename[1],ios::binary);//this line was the culprit..
}

outfile.close();
infile.close();
}
Jul 19 '05 #1
0 1335

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
1
by: Barry | last post by:
Hi Everytime is reinstall Windows XP , Visual Studio .NET and IIS all C# Web Applications stop functioning with the following error message Description: An error occurred during the...
2
by: ThunderMusic | last post by:
Hi, I have a value that contains flags that I must get using a bitmask. I tryied with the && operator, but the compiler outputs this error : Operator '&&' cannot be applied to operands of type...
0
by: Roald | last post by:
I am working on an application that needs to implement logical deletes instead of removing the records permanently. The logical delete works by setting 3 fields (deleted flag, date and user). I...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
14
by: blueboy | last post by:
Hi, I am planning to automate a nighty restore of a DB on another server can someone point me in the right direction with the SQL script to modify the logical file names to the correct path and...
11
by: Dominic Vella | last post by:
I am using MS-Access2000. I can't seem to set the default values for Logical type fields. I start with Dim dbsTmp As Object ' I think it's DAO.Database Set dbsTmp =...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.