Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #147686

Re: What are the odds? (a continuation of One works ...)

Subject Re: What are the odds? (a continuation of One works ...)
Newsgroups comp.lang.c
References (1 earlier) <d3d5se5l55l6abkkm0ja75scmepgsr4p03@4ax.com> <fQBwF.59470$Ko9.7309@fx48.iad> <vvv5sehh7oil3eb5dft8dun7s4t1rbt4h7@4ax.com> <voGwF.93833$vD7.57507@fx06.iad> <g4g6se5u1ggsmecioggck2k7ve59pfdbbp@4ax.com>
From DFS <nospam@dfs.com>
Message-ID <joIwF.86203$FF4.79851@fx40.iad> (permalink)
Organization blocknews - www.blocknews.net
Date 2019-11-06 18:09 -0500

Show all headers | View raw


On 11/6/2019 5:23 PM, Barry Schwarz wrote:
> On Wed, 6 Nov 2019 15:52:28 -0500, DFS <nospam@dfs.com> wrote:
> 
>> On 11/6/2019 1:08 PM, Barry Schwarz wrote:
> 
> <snip>
> 
>>> One of the simplest things you can do that make programming 
>>> exponentially easier is use a consistent indenting scheme.  This
>>> will help you avoid nesting level errors.
>> 
>> 
>> The indenting is fine in my editor, but a mix of tabs and spaces
>> comes out bad when the code is pasted to Thunderbird.
> 
> When asking for help, it behooves one to make things as easy as 
> possible for the reader.  Experienced people in this newsgroup have 
> recommended spaces instead of tabs so that the resulting display is 
> not dependent on how the reader's tabs are set.

I'll do that.



>>>> Maybe you can show me how to fix the //letter distribution part
>>>> of the code.  I can't get it to compile.
>>> 
>>> The error message for the statement that calls strcmp should have
>>> been crystal clear.  What part of it did you not understand?
>> 
>> 
>> I got it:
> 
> You got that part of it but then decided to break another part.

> <snip>
> 
>> //letter distribution char charset[62] = 
>> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 
>> int charsetLen = strlen(charset);
> 
> After numerous examples in your comp.lang.c posts (where I have 
> redirected this response since we are not discussing the odds any 
> more) of calculating charsetLen correctly, 

Actually, I never calculated it before.  I hard-coded it.

short charsetLen = 62;


> you have chosen to use a 
> different method.  You have tried to pass charset to strlen in 
> complete violation of the requirements that function imposes.
> 
> It is not sufficient to simply pass a pointer to char to strlen. 
> strlen requires that the pointer actually point to a string.  In
> order for an array of char to contain a string, the array must
> contain at least one '\0' to properly terminate the string.  charset
> does not. As a result, this code exhibits undefined behavior.


char charset[62]
="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int charsetLen = strlen(charset);
printf("%d \n",charsetLen);
62


char charset[63] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int charsetLen = strlen(charset);
printf("%d \n",charsetLen);
62





> When you tested the code, did you not notice extraneous lines of 
> output after the line for "9"?


Not seeing that.  Compiled and ran on tcc/Windows and gcc (MSYS2) and 
there are no extraneous lines of output after the output for 9.

I do notice on tcc/Windows the count for 9 is always significantly lower 
than the count of any other character in the set.  Low 15Ks vs high 
15Ks/low 16Ks for all the other characters.

That doesn't happen on gcc/MSYS2.


Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: What are the odds? (a continuation of One works ...) Barry Schwarz <schwarzb@delq.com> - 2019-11-06 14:23 -0800
  Re: What are the odds? (a continuation of One works ...) Bart <bc@freeuk.com> - 2019-11-06 22:35 +0000
    Re: What are the odds? (a continuation of One works ...) luser droog <luser.droog@gmail.com> - 2019-11-06 17:09 -0800
    Re: What are the odds? (a continuation of One works ...) Keith Thompson <kst-u@mib.org> - 2019-11-06 19:19 -0800
      Re: What are the odds? (a continuation of One works ...) Ian Collins <ian-news@hotmail.com> - 2019-11-07 16:30 +1300
        Re: What are the odds? (a continuation of One works ...) Bart <bc@freeuk.com> - 2019-11-07 10:59 +0000
        Re: What are the odds? (a continuation of One works ...) David Brown <david.brown@hesbynett.no> - 2019-11-07 14:27 +0100
  Re: What are the odds? (a continuation of One works ...) DFS <nospam@dfs.com> - 2019-11-06 18:09 -0500
    Re: What are the odds? (a continuation of One works ...) Keith Thompson <kst-u@mib.org> - 2019-11-06 19:26 -0800
      Re: What are the odds? (a continuation of One works ...) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-07 11:57 +0000

csiph-web