473,407 Members | 2,359 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,407 software developers and data experts.

Pointer conversion problem

Kat
Ok so I finally fixed most of the problems in this program but I've
come up with even more. My program(if you saw earlier) is a program
for secure file deletion as part of a project. I'm using Visual Studio
6.0(my school refuses to upgrade, I don't know why nor can I persuade
them otherwise) Visual C++.

Here's a snippet of the code I'm having problems with.

//Begin Code\\

long size;

infile.seekg(0,ifstream::end);
size = infile.tellg();
infile.seekg(0);
infile.close();

ofstream outfile (fileloc,ofstream::binary);

outfile.write (zero,size);

//End Code\\

Bellow is the error given by the compiler.

//Begin Error\\

Z:\SecureIO.cpp(172) : error C2664: 'write' : cannot convert parameter
1 from 'const int *' to 'const char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

//End Error\\

How do I fix this problem?

Apr 26 '06 #1
2 1774
Kat wrote:
Ok so I finally fixed most of the problems in this program but I've
come up with even more. My program(if you saw earlier) is a program
for secure file deletion as part of a project. I'm using Visual Studio
6.0(my school refuses to upgrade, I don't know why nor can I persuade
them otherwise) Visual C++.

Here's a snippet of the code I'm having problems with.

//Begin Code\\

long size;

infile.seekg(0,ifstream::end);
size = infile.tellg();
infile.seekg(0);
infile.close();

ofstream outfile (fileloc,ofstream::binary);

outfile.write (zero,size);

//End Code\\

Bellow is the error given by the compiler.

//Begin Error\\

Z:\SecureIO.cpp(172) : error C2664: 'write' : cannot convert parameter
1 from 'const int *' to 'const char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

//End Error\\

How do I fix this problem?


Hi,
How is zero defined? What requirements do you have on "secure file
deletion" - to fill it with \0's or many '0' characters, or perhaps
random bits?

Look at what the compiler tells you, there is the answer to your question.
Regards,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/
Apr 26 '06 #2

"Kat" <Re*************@gmail.com> wrote in message
news:11*********************@y43g2000cwc.googlegro ups.com...
Ok so I finally fixed most of the problems in this program but I've
come up with even more. My program(if you saw earlier) is a program
for secure file deletion as part of a project. I'm using Visual Studio
6.0(my school refuses to upgrade, I don't know why nor can I persuade
them otherwise) Visual C++.

Here's a snippet of the code I'm having problems with.

//Begin Code\\

long size;

infile.seekg(0,ifstream::end);
size = infile.tellg();
infile.seekg(0);
infile.close();

ofstream outfile (fileloc,ofstream::binary);

outfile.write (zero,size);
How is zero defined? By your error message it would seem it's defined as in
integer pointer. But you want to write a character. Is it an array?
Simplest way would be to make zero a character (array?) of '\0' instead of
an int with value 0. Of course the size of it has to be as big as size
though.

I believe what you actually want to do here is write the character '\0' size
times. You can either create an array and initialize it to '\0'
(std::vector<char> perhaps) or put your write in a for loop writing one char
size times.

char zero = '\0';
for ( int i = 0; i < size; ++i )
outfile.write(&zero, size);

is one way of doing it.

An alternative is to simply cast your zero to a char pointer, as long as you
know that it's the proper size. I wouldn't do this, however, I'd just make
it chars.
//End Code\\

Bellow is the error given by the compiler.

//Begin Error\\

Z:\SecureIO.cpp(172) : error C2664: 'write' : cannot convert parameter
1 from 'const int *' to 'const char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast

//End Error\\

How do I fix this problem?

Apr 27 '06 #3

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

Similar topics

9
by: Ben Midgley | last post by:
Please have a look at the code below My problem is the error message "Nonportable pointer conversion", so far as I can tell there is no pointer conversion occuring here so I am assuming it is...
11
by: x-pander | last post by:
given the code: <file: c.c> typedef int quad_t; void w0(int *r, const quad_t *p) { *r = (*p); }
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
48
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
2
by: toton | last post by:
Hi, This is continuation of topic pointer & reference doubt. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca But I...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
6
by: icecrime | last post by:
Hi, I have a small interrogation concerning pointer to integer conversion: how is it possible to safely and portably print a memory address ? From what I understand (according to FAQ 4.14),...
9
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value...
6
by: Lighter | last post by:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to- pointer standard conversionsare not applied to the left expressions"? In 5.18 Comma operator of the C++ standard, there is a...
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
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.