--- Jim Wagner <jim_d_wagner@applelinks.net> wrote:
> Have you checked the exection of the "for" loop in
> the
> debugger?
>
> Jim
>
>
> On 12 Mar 2007 22:10:47 -0700,Tue, 13 Mar 2007
> 05:10:11
> -0000
> "magzky02" <magzky02@yahoo.com> wrote:
> > i would like to get the sum of values of
> characters in a
> > string. I
> > use to get the checksum.
> >
> > ex.
> > strcopy(string1, "abcdefghigklmnopqrstuvwxyz");
> >
> > this does not work:
> >
> > sum=0;
> > for (i = 0; i < strlen(string1); i++)
> > {
> > sum = sum + string[i];
> > }
> >
> > but this works:
> >
> > sum = string1[0] + string1[1] + .... + string[25];
> >
> > but is too lengthy to do the later method.
> > is there any shorter method to get the sum of
> values in a
> > string?
> >
> > regards
> >
> > mago
> >
>
ofcourse it's better to use end of string character,
instead of using strlen for each iteration:
sum = 0;
char c;
for(i=0; (c=s[i]) != '\0'; i++)
sum += c;
____________________________________________________________________________________
Looking for earth-friendly autos?
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/Message
Re: [AVR-Chat] checksum
2007-03-19 by Reza
Attachments
- No local attachments were found for this message.