Jump to content

Dabbling with C


Andy-H

Recommended Posts

I am trying to get this C code to run but keep getting the compiler errors

C:\Documents and Settings\andrew\Desktop>g++ checksum.c -o checksum
checksum.c:33:19: warning: character constant too long for its type
checksum.c:7:19: error: variable or field 'calcchecksum' declared void
checksum.c:7:19: error: '_UCHAR' was not declared in this scope
checksum.c:7:31: error: '_UINT' was not declared in this scope
checksum.c:7:38: error: 'csum' was not declared in this scope

 

 

C is not my language of choice but I need to get this code working and convert it to PHP, currently I have the following, but need a C implementation working to check if it returns the expected result ( Note: the C code is not mine, it's from some documentation, I only coded the main function and added the includes, these _UCHAR datatypes don't seem to be used too often?

 

 


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


#define   SMSCHECKBEGIN 0x6c5a
#define   REQSMSSIZE		98
void calcchecksum(_UCHAR inb, _UINT *csum)
{
for (int i = 0; i < 8; ++i) {
	if (*csum & 1) {
		*csum >>= 1;
		if (!(inb & 1)) *csum ^= 0x8408;
	} else {
		*csum >>= 1;
		if (inb & 1) *csum ^= 0x8408;
	}
inb >>= 1;
}
}


_UINT getchecksum(_UCHAR *ind)
{
_UINT csum = SMSCHECKBEGIN;
for(int i = 0; i < REQSMSSIZE - 2; ++i)
	calcchecksum(ind[i], &csum);


ind[REQSMSSIZE - 2] = (_UCHAR)(csum & 0xff);
ind[REQSMSSIZE - 1] = (_UCHAR)((csum >>  & 0xff);
return csum;
}
int main(int argc, char *argv[])
{
   char check[] = '12820000000A5907010F000B817087267041F8000000000B817087267041F80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFFFF068B\0';
   std::out(getchecksum(check));
}
[/i]

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.