Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > New to C++ and Need a little help with a public domain program

Reply
Thread Tools

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

 
 
OZ
Guest
Posts: n/a
 
      06-26-2004
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
*/

#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,
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-26-2004

"OZ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
OZ
Guest
Posts: n/a
 
      06-26-2004
PLEASE DISREGARD!!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments