473,788 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code doesnt work......pleas e help me..

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..thou gh 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.


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

strcpy(filename[0],file);
strcpy(filename[1],filename[0]);
strcat(filename[1],"0");

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

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

}while(choice== 'q');

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

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

char str[1];

infile.read(str ,1);

char ext[1]="0";

for(int i=0;i<n;i++)
{
ctr=0;
while(ctr<tempp os)
{
outfile.write(s tr,1);
infile.read(str ,1);

ctr++;
}
ext[0]++;
outfile.close() ;
strcpy(filename[1],filename[0]);
strcat(filename[1],ext);
ofstream outfile(filenam e[1],ios::binary);

}

outfile.close() ;
infile.close();
}
Jul 19 '05 #1
1 1683
Josh Sebastian wrote:
void breaker()
{
long int temppos = 0,pos = 0;
int n = 0;
char choice =' ';
char file[20] = "input.zip",fil ename[2][30];
char byte[1] = " " ;

Ouch! Buffer overflow already. The string " " has two characters: ' ' and
'\0'. You tried to store it in an array that can hold only one character.


No. It's a constraint violation that should not compile.
8.5.2 Character arrays [dcl.init.string]

2 There shall not be more initializers than there are array elements.
[Example:
char cv[4] = "asdf"; // error
is ill-formed since there is no space for the implied trailing '\0'.
]
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #2

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

Similar topics

6
6717
by: | last post by:
Hello, I hope someone will help me or I will have to dive from 11th floor. Why this --> test = @"Melanie "Jets" Riggs" doesnt work in asp? I need something like that and I dont know how to make it work. Please help me!! answer to dan@syscz.com many thanx
7
3615
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
17
2719
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
3
2291
by: funfair | last post by:
Hi, I'm facing a strange problem in access 2003 i dont know how to solve it i have a code in VB which give an autonumber but in finanical new year it reset to 1 on new year it works in one form but the same code doesnt work in other form in run time it's going to skip if satatement of date part to check if month is 4 or not what is the problem ? i have looked in the net and i read somehting about reference what should i do about it .
0
1519
by: jmacduff | last post by:
Big question: How to enable edit/update commands to work when setting the sqldatasource select command from code behind. Details: I have a GridView using a sqldatasouce with the select and update commands set. The gridview is part of a "admin" page where the admin will view the data, then use the gridview edit/update buttons to update the data.......that all works great.
1
2081
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set <char> open it doesnt take any char values into it and says cannot convert char to const char... I wonder why is it converting char to const char when I have declared that it shud be of type char...It doesnt work with int either,.. Please help...
8
1698
by: wastedhello | last post by:
ok. here are a list of things i cant fix. ive been trying for way to long now. 1. if more then 1000 values are told, will still continue with program. 2. if -max, min, average etc run, and 2 values are given they will work, but will cause a random segmentation fault. (BUT only with giving two values.) 3. -average doesnt give average. 4. -gta is ment to give all the values greater then the average. but doesnt do anything 5. -gt is ment...
1
2554
by: Ivan Ven Osdel | last post by:
The free Python editors/IDEs really do need work as far as code completion goes but I am hopeful. IMO Stani's Python Editor comes closest by providing some code sense through a combination of history and doc strings for Python built-ins. Where it falls short is the ability to scan doc strings for your own code and non built-in modules in the Python path. Python already has the ground work in place to accomplish something similar to VS's XML...
5
2093
by: slizorn | last post by:
hi, well this is the file i have to read into the system... <matrix> rows = 2 cols = 2 1 2 2 4 </matrix>
3
1697
by: Tahir | last post by:
Hi, i am delevoping an ASP.NET website which worked well on my old web host and now working on localhost but now it doesnt works on my new host. i have new registered and ftp the files that work on previous host. now it shows the classic runtime eror page which explains how to enable customerrors tag. the problem is my website is configured to show my custom error page. what is the problem? why the customerors tag doesnt work?
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.