Results 1 to 3 of 3

Thread: Extracting Characters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Basingstoke
    Posts
    86

    Question Extracting Characters

    Help!!!

    char FormatID(unsigned char *pString, unsigned char *sStringOfChars)
    {
    int i;
    int nChr;
    int nTot;
    int nDigit;

    nTot = 0;
    for (i = 0; i < 9; i++)
    {
    nChr = character i of pString
    if (nChr > 0) nTot += (nChr * (23 - (i + 1)));
    }
    nDigit = (23 - (nTot % 23));
    return character nDigit of sStringOfChars
    }

    Not done any C++ for years, cannot remember a thing (doh!).
    Anyone help with the above two lines :
    nChr = ...
    return ...

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Not sure exactly what the function is supposed to do, but in general:
    Code:
    c = SomeString[n]; // copies the n'th char of SomeString to c, where n is zero-based

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    This is like a checksum module.

    Try:
    Code:
    char FormatID(unsigned char *pString, unsigned char *sStringOfChars)
    {
              int i=0;
              char *nChr;
              int nTot=0;
              for (nChr=pString,i=0; i<9;i++,nChr++){
              	if(*nChr) nTot+=(nChr*(23-(i + 1)));
              }
              return (char)(23-(nTot % 23));
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width