[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Kode der aldrig bliver kxrt?



Karl Pálsson wrote:
> 
> Ja, det er en bug.

Nej det er ikke en bug - et int array på [2] er 0,1 og 2 - da plads [2]
ikke behøver at være NULL (læs '\0') da '\0' er NULL = 0, derfor er det
ikke en bug.

Dette lille program beviser det:

#include <iostream> 
void main() 
{ 
  int sum[2]; 
  for (int x=0;x<3;x++) 
    sum[x]=x; 
  for (int x=0;x<3;x++) 
    cout << x << endl;
}




> 
> Jeg har følgende kode-stump fra gnu-barcode, Interleave 2 of
> 5:
>     int i, sum[2], textpos, usesum = 0;
>     if ((bc->flags & BARCODE_NO_CHECKSUM)) usesum = 0; else
> usesum = 1;
....

> if (usesum) {
>   sum[0] = sum[1] = 0;
>   for (i=0; text[i]; i++)
>    sum[i%2] += text[i]-'0'; // kun sum[0] og sum[1] tilskrives
>    if (strlen(text) % 2)
>      i = sum[0] * 3 + sum[1]; // denne linie køres ikke
>    else
>      i = sum[1] * 3 + sum[2]; // denne linie køres altid
>      strcat(text, "0");
>      if (i%10)
>        text[strlen(text)-1] += 10-(i%10);
> }

Hvor stor er text[] arrayet ?? hvis det er større end 2 så er det der
fejlen er.

> Har jeg fundet en bug?

Nope - desværre ikke med sum[] arrayet !!!


-- 
Bjarke Bruun - E-mail: sslug@sslug http://linux.hhknet.dk
   __
  / /  (_)__  __ ____  __
 / /__/ / _ \/ // /\ \/ /  . . .  t h e   c h o i c e   o f   a
/____/_/_//_/\_,_/ /_/\_\              G N U   g e n e r a t i o n . . .


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *