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

New to C++ and Need a little help with a public domain program

OZ
Hi,

I am new C++ and need a little help with a public domain program that
is suppose to perform a byte swap. I am receiving the following error
messages during the compile process with Microsoft C++ 2003.

Here are the error messages and source code:
(97) : error C2664: 'fgetpos' : cannot convert parameter 2 from 'void
*' to 'fpos_t *'

Conversion from 'void*' to pointer to non-'void' requires an explicit
cast

(99) : error C2440: '=' : cannot convert from 'void *' to 'unsigned
char *'

Conversion from 'void*' to pointer to non-'void' requires an explicit
cast
Here is the source:

/*
* swap Version 0.0
* Bart Trzynadlowski, October 27, 2000
* Public domain
*
* June 11, 2001:
* - Updated contact information
*
*
* This program swaps the bytes, words, doublewords, or quadwords in
files.
*
* Usage: swap <-b files, -w files, -d files, -q files>
* Options: -?,-h Show help
* -b Byte swap (8-bit) [default]
* -w Word swap (16-bit)
* -d Doubleword swap (32-bit)
* -q Quadword swap (64-bit)
*
* Contact Bart Trzynadlowski:
* Email: tr**@mailandnews.com
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int swap_type = 0; /* 0=byte, 1=word, 2=dword, 3=qword */
unsigned mask[] = { 0, 1, 3, 7 };
unsigned data_sz[] = { 1, 2, 4, 8 };
char *type_l[] = { "byte", "word", "doubleword", "quadword" };
char *type_u[] = { "Byte", "Word", "Doubleword", "Quadword" };
void Swap(unsigned char *buffer, unsigned size, char *file)
{
unsigned i, j;
unsigned char d[8];

if (size & mask[swap_type])
{
fprintf(stderr, "swap: File cannot be %s-swapped: %s (%d
bytes)\n",
type_l[swap_type], file, size);
return;
}

printf("swap: %s-swapping file: %s (%d bytes)... ",
type_u[swap_type],
file, size);
for (i = 0; i < size; i += (data_sz[swap_type] * 2))
{
for (j = 0; j < data_sz[swap_type]; j++)
d[j] = buffer[i + j];
for (j = 0; j < data_sz[swap_type]; j++)
buffer[i + j] = buffer[i + j + data_sz[swap_type]];
for (j = 0; j < data_sz[swap_type]; j++)
buffer[i + j + data_sz[swap_type]] = d[j];
}
printf("OK\n");
}

void ShowHelp()
{
printf("swap Version 0.0 by Bart Trzynadlowski: Data-Swapping
Utility\n");
printf("Usage: swap <-b files, -w files, -d files, -q
files>\n");
printf("Options: -?,-h Show this help text\n");
printf(" -b Swap bytes [default]\n");
printf(" -w Swap words\n");
printf(" -d Swap doublewords\n");
printf(" -q Swap quadwords\n");
exit(0);
}

int main(int argc, char **argv)
{
FILE *fp;
unsigned char *buffer;
unsigned i, j;

if (argc <= 1)
ShowHelp();

setvbuf(stdout, NULL, _IONBF, NULL);

for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-?") || !strcmp(argv[i], "-h"))
ShowHelp();
else if (!strcmp(argv[i], "-b")) swap_type = 0;
else if (!strcmp(argv[i], "-w")) swap_type = 1;
else if (!strcmp(argv[i], "-d")) swap_type = 2;
else if (!strcmp(argv[i], "-q")) swap_type = 3;
else
{
if ((fp = fopen(argv[i], "rb+")) == NULL)
fprintf(stderr, "swap: Failed to open file: %s\n",
argv[i]);
else
{
fseek(fp, 0, SEEK_END);
ERROR HERE-> fgetpos(fp, (void *) &j);
rewind(fp);
ERROR HERE-> if ((buffer = calloc(j, sizeof(unsigned char))) ==
NULL)
fprintf(stderr, "swap: Failed to allocate %d bytes
of "
"memory for file: %s\n", j,
argv[i]);
else
{
fread(buffer, sizeof(unsigned char), j, fp);
rewind(fp);
Swap(buffer, j, argv[i]);
fwrite(buffer, sizeof(unsigned char), j, fp);
free(buffer);
}
fclose(fp);
}
}
}

setvbuf(stdout, NULL, _IOLBF, NULL);

return 0;
}

Any information would would be greatly appreciated.

Thanks,
Jul 22 '05 #1
2 2152

"OZ" <ob*****@sandstorment.com> wrote in message
news:7b**************************@posting.google.c om...
Hi,

I am new C++ and need a little help with a public domain program that
is suppose to perform a byte swap. I am receiving the following error
messages during the compile process with Microsoft C++ 2003.


The program is C not C++. Make sure you call the file something.c not
something.cpp and you should be OK.

Since it is C not C++ take any further questions to news:comp.lang.c

john
Jul 22 '05 #2
OZ
PLEASE DISREGARD!!!!
Jul 22 '05 #3

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

Similar topics

0
by: Christopher Ambler | last post by:
This is long, but it's driving me nuts. I need some adult supervision :-) (and I'm not above bribing for help) I have a stored procedure that I call that returns XML to me. The SP returns 3...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
2
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
2
by: jeremiah johnson | last post by:
I have a .net DLL that I've created (based on someone's post in this group, sorry I've forgotten who) and I need a little help with making it work. I want to provide the same functionality as...
3
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we...
2
by: shuisheng | last post by:
Dear All, Assume I have a class for a cuboid domain. The domain is defined by the cuboid's lower corner, such as (0, 0, 0), and upper corner, such as (1, 1, 1). The upper corner should be always...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
4
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.