Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Translating C++ FOR cycle into Foxpro code
Message
De
05/12/1997 16:27:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00064105
Message ID:
00064134
Vues:
57
Yes it's right as long as you take into account that C arrays start with 0.
In C array[0] is first element while in FP array[1]. And C threats strings as zero ended arrays.
Cetin
>Cetin,
>Thanks but more importantly I need to know if I'm doing this the right way:
>c:
>digit = *(tempCustStr + i) - '0'
>
>foxpro:
>digit = VAL(SUBST(tempCustStr,i,1))
>
>Thanks
>
>Gil
>
>
>>>>
>>>>*Sample value:
>>>>tempCustStr = '50400000019'
>>>>
>>>>****C++ code:******
>>>>rhs = 0
>>>>for (i = strlen(tempCustStr)-1;i>=0;i--){
>>>> digit = *(tempCustStr + i) - '0'
>>>> if (i % 2 == 0) {
>>>> rhs += digit;
>>>> //odd digits
>>>> } else {
>>>> rhs += (2 * digit) /10 + (2 * digit) % 10;
>>>> }
>>>>}
>>>>
>>>>rhs = 99 - rhs
>>>>checkdigit = rhs / 10
>>>>lastdigit = rhs % 10
>>>>
>>>>****My FP code: (It's not working properly)******
>>>>rhs = 0
>>>>i = LEN(tempCustStr) - 1
>>i = LEN(tempCustStr)
>>>>DO WHILE i >= 0
>>DO WHILE i > 0 && C counting starts with 0, Fox 1
>>>> digit = VAL(SUBST(tempCustStr,i,1))
>>>> IF i % 2 = 0
>>>> rhs = rhs + digit
>>>> ELSE
>>>> rhs = rhs + ((2 * digit)/10) + ((2 * digit) % 10)
>>>> ENDIF
>>>> i = i - 1
>>>>ENDDO
>>>>
>>>>rhs = 99 - rhs
>>>>checkdigit = rhs /10
>>>>lastdigit = rhs % 10
>>>>
>>>>Thanks a lot, I really appreciate any help
>>
>>>>
>>>>Have a good day,
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform