char conversion problem

From: muser (charlie12345_at_hotmail.com)
Date: 12/17/03


Date: 17 Dec 2003 10:08:51 -0800

is string converted to its integer equivalent by minusing it by 48?
the function is suppose to check the fifth digit of struct member
using the formula contained within the function.
The function isn't doing that at the moment, hence this post and the
querie above. string must be of type char.

bool checkdigitforcustomercode( char* string )
{

int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

for(int i =0; i < 5; ++i)
 check1 += (string[i] - 48) * weightingfactor;/* problem area */
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

for(i=4; i<=5; i++)
if(!string[i] == checkdigit)
return false;

if(checkdigit == 11){
checkdigit = 'X';
}
else
         if(checkdigit = 10){
  checkdigit = '0';
  }

return true;
}



Relevant Pages

  • Re: char conversion problem
    ... The checkdigit is correct, ... I check the char string variable, ... int checkdigit; ... A single character might be, depending on the character set in use, ...
    (comp.lang.cpp)
  • Re: Linked list w/ structure
    ... I have no problem when first_name in the structure is an int. ... typedef struct member ... RECORD *head, *p; ... Language: C ...
    (comp.lang.c)
  • Linked list w/ structure
    ... I have no problem when first_name in the structure is an int. ... typedef struct member ... RECORD *head, *p; ... Language: C ...
    (comp.lang.c)
  • Struct member undetected by compiler
    ... when I run the code below, it gives the compiler error at the bottom of ... I am not sure why it cann't see the struct member. ... 5-0.cpp: In function `int main': ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Fat pointers
    ... Taking the address of a struct member? ... (You don't need to change any compilers, just say, "this ... following code invoke undefined behavior? ... struct foo {int a,b,c;} bar; ...
    (comp.lang.c)