Andy-H Posted November 8, 2011 Share Posted November 8, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/250687-dabbling-with-c/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.