• Small challenge: sort names

    From DFS@nospam@dfs.com to comp.lang.c on Tue Apr 7 23:14:41 2026
    From Newsgroup: comp.lang.c

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast,
    James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson,
    Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.















































































    ------------------------------------------------------------------
    No peeking!
    ------------------------------------------------------------------
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char names[2000] = {"Martin Hohenberg, Jae Yang, Tim Bando, Daniel
    Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit,
    Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher
    Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane
    Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012,
    John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova"};


    //count characters in a string
    int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return cnt;}

    //compare for qsort
    int comparechar( const void *a, const void *b)
    {
    const char **chara = (const char **)a;
    const char **charb = (const char **)b;
    return strcasecmp(*chara, *charb);
    //return strcmp(*chara, *charb);
    }


    //left trim spaces
    void ltrim(char *str)
    {
    int totrim = strspn(str," ");
    if (totrim > 0)
    {
    int len = strlen(str);
    if (totrim == len)
    { str[0] = '\0'; }
    else
    {memmove(str, str + totrim, len + 1 - totrim);}
    }
    }


    int main(void)
    {

    //vars
    char delim[2] = ",";
    int i=0,j=0;

    //number of names is commas + 1
    int namecnt = countchr(names,',') + 1;

    //name array: one column for first-last, one for last-first
    char *narr[2][namecnt];

    char *flname, lfname[30]; // full names
    char *fname, *lname; // part names
    char tmp[30]="";

    // parse full names from string
    // then parse first and last from full name
    // add both into array
    char *dup = strdup(names);
    while((flname = strsep(&dup,delim)) != NULL )
    {
    ltrim(flname);
    if(countchr(flname,' ')>0)
    {
    lname = strrchr(flname,' ')+1;
    memset(tmp, '\0', sizeof(tmp));
    strncat(tmp,flname,strlen(flname)-strlen(lname)-1);
    fname = strdup(tmp);
    }
    else
    {
    lname = strdup(flname);
    fname = strdup("");
    fname[strlen(fname)-2] = '\0';
    }

    sprintf(lfname,"%s %s",lname,fname);
    narr[0][i]= strdup(flname);
    narr[1][i]= strdup(lfname);
    i++;
    }


    //add list of last-first names into array then sort it
    char *sarr[namecnt];
    for(i=0;i<namecnt;i++) {sarr[i] = narr[1][i];}
    qsort(sarr, namecnt, sizeof(char*), comparechar);

    //print first-last in order by last-first
    for(i=0;i<namecnt;i++)
    {
    for(j=0;j<namecnt;j++)
    {
    if(narr[1][j] == sarr[i])
    {
    printf("%d %s\n",i+1, narr[0][j]);
    break;
    }
    }
    }

    return 0;
    }
    ------------------------------------------------------------------
    71 SLOC

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Wed Apr 8 10:22:14 2026
    From Newsgroup: comp.lang.c

    On 2026-04-08 05:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last [name] (as shown above) but ordered by last first.

    In cases like this where data with Latin and Greek characters are
    mixed you should clarify or even define how the comparison function
    shall operate on mixed data to create a "correct" ordering.

    Hereabouts we usually insert the "Άρης Δάσος" (starting with the letter Delta) before or after the letter 'D'; i.e. using an implicit transcription. But this may not suit other cases. Or artificial ones
    like this challenge, so you should probably clarify for folks who
    are interested to re-implement (or use) a sorting function in "C"
    (with or without a locale setting to do the dirty work).

    ------------------------------------------------------------------
    No peeking!
    [...removed without peeking...]
    71 SLOC
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)

    Honestly; mind to explain what the point of this "C" challenge is?

    (From the application user's perspective the most interesting thing
    would be a sophisticated handling of "mixed locales", but I assume
    you're just using what C's 'str*cmp' functions technically provide
    with whatever environment setting, and the challenge is something
    else?)

    Janis

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From DFS@nospam@dfs.com to comp.lang.c on Wed Apr 8 12:25:17 2026
    From Newsgroup: comp.lang.c

    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:
    On 2026-04-08 05:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George
    Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten,
    Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang,
    Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens
    Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang,
    Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon,
    Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip
    Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal
    Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William
    Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης
    Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les
    Vogel, Matt Pollard, Andres Cordova


    Print first last [name] (as shown above) but ordered by last first.

    In cases like this where data with Latin and Greek characters are
    mixed you should clarify or even define how the comparison function
    shall operate on mixed data to create a "correct" ordering.

    Hereabouts we usually insert the "Άρης Δάσος" (starting with the letter Delta) before or after the letter 'D'; i.e. using an implicit transcription. But this may not suit other cases. Or artificial ones
    like this challenge, so you should probably clarify for folks who
    are interested to re-implement (or use) a sorting function in "C"
    (with or without a locale setting to do the dirty work).

    ------------------------------------------------------------------
    No peeking!
    [...removed without peeking...]
    71 SLOC
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)


    Bulky C is more fun!

    "one-liner"? With multiple pipes and tr and sed and awk, maybe.



    Honestly; mind to explain what the point of this "C" challenge is?

    Sure thing: "Print first last (as shown above) but ordered by last first."

    (From the application user's perspective the most interesting thing
    would be a sophisticated handling of "mixed locales", but I assume
    you're just using what C's 'str*cmp' functions technically provide
    with whatever environment setting, and the challenge is something
    else?)

    Just looking to see how a variety of excellent C programmers would
    approach a string/split/sort challenge.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bart@bc@freeuk.com to comp.lang.c on Wed Apr 8 18:57:46 2026
    From Newsgroup: comp.lang.c

    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:
    On 2026-04-08 05:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle
    Burkholder, Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams,
    George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave
    Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher
    Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant,
    Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu
    Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan
    Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale
    Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey
    Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark
    Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius
    Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas, Bill Soistman,
    ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous,
    Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last [name] (as shown above) but ordered by last first.

    In cases like this where data with Latin and Greek characters are
    mixed you should clarify or even define how the comparison function
    shall operate on mixed data to create a "correct" ordering.

    Hereabouts we usually insert the "Άρης Δάσος" (starting with the
    letter Delta) before or after the letter 'D'; i.e. using an implicit
    transcription. But this may not suit other cases. Or artificial ones
    like this challenge, so you should probably clarify for folks who
    are interested to re-implement (or use) a sorting function in "C"
    (with or without a locale setting to do the dirty work).

    ------------------------------------------------------------------
    No peeking!
    [...removed without peeking...]
    71 SLOC
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)


    Bulky C is more fun!

    "one-liner"?  With multiple pipes and tr and sed and awk, maybe.



    Honestly; mind to explain what the point of this "C" challenge is?

    Sure thing: "Print first last (as shown above) but ordered by last first."

    (From the application user's perspective the most interesting thing
    would be a sophisticated handling of "mixed locales", but I assume
    you're just using what C's 'str*cmp' functions technically provide
    with whatever environment setting, and the challenge is something
    else?)

    Just looking to see how a variety of excellent C programmers would
    approach a string/split/sort challenge.


    These are more higher level tasks than you'd want to use C for. And
    everyone's going to do it a slightly different way.

    You also seem to value LoC as a metric. Your version was labeled as 71
    SLOC, I assume including this function:

    //count characters in a string
    int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a string
    (like the comment says)? But strlen will do that. Then I noticed that
    the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it returned 1,
    not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Now it's clearer! It's counting occurrences of 'chr' within 'str'.

    This adds 6 SLOC, but IMO it's worth it. Striving to get the smallest
    LOC meant poorer quality code, not helped by the misleading comment, or
    the choice of 'c' as the index.

    I'd write it like this:

    int countchr(char *s, char ch) {
    int n = 0;
    while (*s) {
    if (*s == ch) n++;
    ++s;
    }
    return n;
    }

    Then if worried about line-count, I might try:

    int countchr(char *s, char ch) {
    int n = 0;
    while (*s) n += (*s++ == ch);
    return n;
    }

    This is actually 12 characters shorter when your version, even with space-based indents (normally I use hard tabs) and extra white space.


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.lang.c on Wed Apr 8 21:04:56 2026
    From Newsgroup: comp.lang.c

    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a string >(like the comment says)? But strlen will do that. Then I noticed that
    the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it returned 1,
    not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }



    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Michael S@already5chosen@yahoo.com to comp.lang.c on Thu Apr 9 00:10:30 2026
    From Newsgroup: comp.lang.c

    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int
    c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a
    string (like the comment says)? But strlen will do that. Then I
    noticed that the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it
    returned 1, not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }




    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }




    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From DFS@nospam@dfs.com to comp.lang.c on Wed Apr 8 17:13:17 2026
    From Newsgroup: comp.lang.c

    On 4/8/2026 1:57 PM, Bart wrote:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:
    On 2026-04-08 05:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle
    Burkholder, Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams,
    George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave
    Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher
    Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant,
    Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu
    Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken
    LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan
    Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale
    Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey
    Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark
    Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius
    Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas, Bill Soistman,
    ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous,
    Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last [name] (as shown above) but ordered by last first.

    In cases like this where data with Latin and Greek characters are
    mixed you should clarify or even define how the comparison function
    shall operate on mixed data to create a "correct" ordering.

    Hereabouts we usually insert the "Άρης Δάσος" (starting with the >>> letter Delta) before or after the letter 'D'; i.e. using an implicit
    transcription. But this may not suit other cases. Or artificial ones
    like this challenge, so you should probably clarify for folks who
    are interested to re-implement (or use) a sorting function in "C"
    (with or without a locale setting to do the dirty work).

    ------------------------------------------------------------------
    No peeking!
    [...removed without peeking...]
    71 SLOC
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)


    Bulky C is more fun!

    "one-liner"?  With multiple pipes and tr and sed and awk, maybe.



    Honestly; mind to explain what the point of this "C" challenge is?

    Sure thing: "Print first last (as shown above) but ordered by last
    first."

    (From the application user's perspective the most interesting thing
    would be a sophisticated handling of "mixed locales", but I assume
    you're just using what C's 'str*cmp' functions technically provide
    with whatever environment setting, and the challenge is something
    else?)

    Just looking to see how a variety of excellent C programmers would
    approach a string/split/sort challenge.


    These are more higher level tasks than you'd want to use C for.

    ? string.h exists for a reason.


    And everyone's going to do it a slightly different way.

    That's what I'm hoping.


    You also seem to value LoC as a metric. Your version was labeled as 71
    SLOC, I assume including this function:

    //count characters in a string
    int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return cnt;}

    I couldn't quite figure out what it did; counting characters in a string (like the comment says)? But strlen will do that. Then I noticed that
    the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it returned 1,
    not 4 or 5.

    So I refactored it like this:

      int countchr(char *str, char chr) {
          int c=0, cnt=0;
          while (str[c]!='\0') {
              if (str[c] == chr) cnt++;
              c++;
          }
          return cnt;
       }

    Now it's clearer! It's counting occurrences of 'chr' within 'str'.

    Yep. My description was bad.


    This adds 6 SLOC, but IMO it's worth it. Striving to get the smallest
    LOC meant poorer quality code, not helped by the misleading comment, or
    the choice of 'c' as the index.

    I'd write it like this:

      int countchr(char *s, char ch) {
          int n = 0;
          while (*s) {
              if (*s == ch) n++;
              ++s;
          }
          return n;
      }

    Then if worried about line-count, I might try:

      int countchr(char *s, char ch) {
          int n = 0;
          while (*s) n += (*s++ == ch);
          return n;
      }

    This is actually 12 characters shorter when your version, even with space-based indents (normally I use hard tabs) and extra white space.

    Cool improvements.

    But no code for the challenge? I know it looks lame at first, but it's actually kind of painful to figure out.

    And I notice I didn't specify the output format. I want it to look like
    this:

    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mordant
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping


    If you have any high-level or low-level challenges, post them. Seeing
    other approaches, discussing them, refining my code... it's my favorite
    way to use/learn C.

    The CSES Problem Sets and Project Euler are good, too, but they're more
    lonely endeavors.

    Thanks for the feedback.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.lang.c on Wed Apr 8 23:35:35 2026
    From Newsgroup: comp.lang.c

    Michael S <already5chosen@yahoo.com> writes:
    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int
    c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a
    string (like the comment says)? But strlen will do that. Then I
    noticed that the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it
    returned 1, not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }




    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Michael S@already5chosen@yahoo.com to comp.lang.c on Thu Apr 9 02:59:01 2026
    From Newsgroup: comp.lang.c

    On Wed, 08 Apr 2026 23:35:35 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Michael S <already5chosen@yahoo.com> writes:
    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int
    c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a
    string (like the comment says)? But strlen will do that. Then I
    noticed that the extra 'chr' parameter, so maybe it stops at
    'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it
    returned 1, not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }




    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.


    Which is irrelevant in this specific case.
    BTW, I think that (ptr != 0) is guaranteed to work even on systems with
    null pointers not being numerically zero. But I am not certain about it.
    What I am certain is that on the right side of assignment to pointer 0
    always acts the same as NULL.
    But that's too irrelevant for our case.

    As to being pedantic w.r.t. '\0', may be you acquired this habit
    because of C++? If I am not mistaken, in C++ '\0' has type char and due
    to that (or because of, which is IMHO, more appropriate wording) can in
    some contexts lead to results different from 0, with differences as huge
    as call to completely different procedure. It does not happen in C where
    we have no misfeature of type based static polymorphism.


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c on Wed Apr 8 17:27:37 2026
    From Newsgroup: comp.lang.c

    scott@slp53.sl.home (Scott Lurndal) writes:
    Michael S <already5chosen@yahoo.com> writes:
    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int
    c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a
    string (like the comment says)? But strlen will do that. Then I
    noticed that the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it
    returned 1, not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }

    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    I wouldn't, but it's a matter of taste.

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    I'd probably use 0 rather than 0u for an initial value of a size_t
    object. 0u is probably going to have to be converted anyway (unless
    size_t happens to be unsigned int). I don't mind relying on the
    implicit conversion in `size_t count = 0;`.

    But for `*str != 0`, I prefer `*str != '\0'` -- not because it
    matters to the compiler (it doesn't), but because I find it easier
    to read. I like the visible reminder that it's a character value.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.

    It does. A constant 0 is always a null pointer constant.
    Converting an NPC to a pointer type, implicitly or explicitly,
    always yields a null pointer value, regardless of how null pointer
    values happen to be represented. But I still prefer using NULL
    (or nullptr in C23 or C++) when I want a null pointer value.
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Wed Apr 8 18:46:00 2026
    From Newsgroup: comp.lang.c

    DFS <nospam@dfs.com> writes:

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George
    Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten,
    Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang,
    Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens
    Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang,
    Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon,
    Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip
    Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal
    Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, ????
    ?????, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les
    Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.

    My solution breaks down as follows

    3 three #include lines
    4 four blank lines between functions (or #include)
    12 four functions, each with three non-body lines
    10 one function (main) with 10 lines in its body
    2 one function with 2 lines in its body
    2 two functions with 1 body line each
    ----
    33 total lines


    Style observed

    Lines at most 79 characters
    Only one statement or declaration per line, except after for() or if()
    a single-statement body is allowed on same line, if everything fits
    Exactly one blank line before each function
    Indented nested blocks (eg, after for()) always use braces, 1TBS
    No blank lines inside functions
    All functions other than main() defined before use (the opposite
    of my preferred style)
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Wed Apr 8 22:14:25 2026
    From Newsgroup: comp.lang.c

    scott@slp53.sl.home (Scott Lurndal) writes:

    Michael S <already5chosen@yahoo.com> writes:

    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Bart <bc@freeuk.com> writes:

    On 08/04/2026 17:25, DFS wrote:

    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int
    c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a
    string (like the comment says)? But strlen will do that. Then I
    noticed that the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it
    returned 1, not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }

    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation.

    A dangerous habit if followed out of habit. For example:

    size_t ones = -1; // makes 'ones' be all one bits
    size_t ones = -1u; // oops! can be 32 ones rather than 64

    I always explicitly check against NULL rather than using !ptr,
    for example.

    I consider the treatment of null pointers and the way if(), for(),
    while(), etc, work to be a pleasing symmetry and an elegant
    simplifying principle of the C language. Pointers are a special
    kind of multi-valued booleans. Writing this

    char *p = ...;
    if( p != NULL ) ...

    is just as repugnant as this

    _Bool b = ...;
    if( b != false ) ...

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.

    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c on Thu Apr 9 02:19:22 2026
    From Newsgroup: comp.lang.c

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]
    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.

    Any C implementation where !ptr does the wrong thing almost certainly
    does not exist. It's difficult to imagine that a C compiler with
    such a fundamental bug would ever go out the door.

    It's barely possible that compiler that uses a representation other
    than all-bits-zero for null pointers might have such a bug, but
    (a) anyone creating such an implementation will almost certainly
    be extremely careful to get such things right, and (b) I'm not sure
    that any such compilers even exist, except perhaps for old systems
    that would be considered exotic today.
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From James Kuyper@jameskuyper@alumni.caltech.edu to comp.lang.c on Thu Apr 9 06:29:19 2026
    From Newsgroup: comp.lang.c

    On 2026-04-08 19:59, Michael S wrote:
    ...
    BTW, I think that (ptr != 0) is guaranteed to work even on systems with
    null pointers not being numerically zero. But I am not certain about it.
    What I am certain is that on the right side of assignment to pointer 0
    always acts the same as NULL.

    An integer constant expression with a value of 0 is a null pointer
    constant. As such, when it appears in certain contexts (comparison with
    a pointer type being one of them) it is implicitly converted to the
    appropriate pointer type. When any null pointer constant is converted to pointer type, the result is guaranteed to be a null pointer. All null
    pointers compare equal to each other, and unequal to any pointer to an
    actual object or function.
    Note, in particular, that this applies even in cases such as
    if(condition) where the condition is implicitly compared for equality
    with 0.

    These rules do NOT apply to non-constant expressions with integer type
    and a value of 0. Of course, on many systems, those are in fact treated
    the same as null pointer constants, which often leads people to write
    code assuming incorrectly that they are required to be treated the same.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.lang.c on Thu Apr 9 15:06:50 2026
    From Newsgroup: comp.lang.c

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]
    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.

    Any C implementation where !ptr does the wrong thing almost certainly
    does not exist. It's difficult to imagine that a C compiler with
    such a fundamental bug would ever go out the door.

    It's barely possible that compiler that uses a representation other
    than all-bits-zero for null pointers might have such a bug, but
    (a) anyone creating such an implementation will almost certainly
    be extremely careful to get such things right, and (b) I'm not sure
    that any such compilers even exist, except perhaps for old systems
    that would be considered exotic today.

    Or even obsolete. The systems in question were all retired by
    2010, and never had a C compiler. The system was BCD and the
    six digit 'undigit' value of EEEEEE was chosen as the NIL (NULL)
    pointer value.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.lang.c on Thu Apr 9 15:15:49 2026
    From Newsgroup: comp.lang.c

    In article <20260409025901.00002bc6@yahoo.com>,
    Michael S <already5chosen@yahoo.com> wrote:
    On Wed, 08 Apr 2026 23:35:35 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Michael S <already5chosen@yahoo.com> writes:
    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    [snip]

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }




    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.

    Which is irrelevant in this specific case.
    BTW, I think that (ptr != 0) is guaranteed to work even on systems with
    null pointers not being numerically zero. But I am not certain about it.
    What I am certain is that on the right side of assignment to pointer 0
    always acts the same as NULL.
    But that's too irrelevant for our case.

    It's easy enough to verify looking at a canonical source.
    Section 6.3.2.3 coupled with 6.5.9 of C18 suggest this is
    guaranteed to work.

    As to being pedantic w.r.t. '\0', may be you acquired this habit
    because of C++? If I am not mistaken, in C++ '\0' has type char and due
    to that (or because of, which is IMHO, more appropriate wording) can in
    some contexts lead to results different from 0, with differences as huge
    as call to completely different procedure. It does not happen in C where
    we have no misfeature of type based static polymorphism.

    '\0' is indeed a `char` in C++. But I don't think that really
    changes the point, which is more about semantics. Why NOT use a
    relevant character constant instead of `0`? It's not whether
    one can or not, or whether it's semantically equivalent, or
    whether C's `char` type is really an integer in a trenchcoat:
    it's using the appropriate constant to match the domain: in this
    case, matching character data.

    - Dan C.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Sat Apr 11 08:31:11 2026
    From Newsgroup: comp.lang.c

    On 2026-04-08 18:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)

    Bulky C is more fun!

    Well, opinions differ. I indeed like little obfuscated challenges.
    But for production code (whether professional or personal) clear
    code is preferable.


    "one-liner"?  With multiple pipes and tr and sed and awk, maybe.

    It depends. If the entries are in one line each it's just 'sort'.

    If you have them all in a one line I'd usually use simply a 'sed'
    to create lines, and if the output shall be in lines again, then
    another 'sed'. That's all. (Less that 60 characters for all.)


    Honestly; mind to explain what the point of this "C" challenge is?

    Sure thing: "Print first last (as shown above) but ordered by last first."

    That doesn't explain the point of such primitive "challenges".
    (But never mind.)

    As noted with a previous "challenge" I see neither a challenge
    for the "C" language, nor an algorithmic challenge here. (YMMV.)

    Janis

    [...]

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Sat Apr 11 08:44:00 2026
    From Newsgroup: comp.lang.c

    On 2026-04-08 23:04, Scott Lurndal wrote:
    Bart <bc@freeuk.com> writes:
    On 08/04/2026 17:25, DFS wrote:
    On 4/8/2026 4:22 AM, Janis Papanagnou wrote:

    //count characters in a string
    int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    I couldn't quite figure out what it did; counting characters in a string
    (like the comment says)? But strlen will do that. Then I noticed that
    the extra 'chr' parameter, so maybe it stops at 'chr'.

    But when I tried running it as countchr("ABCDEFGH", 'E'), it returned 1,
    not 4 or 5.

    So I refactored it like this:

    int countchr(char *str, char chr) {
    int c=0, cnt=0;
    while (str[c]!='\0') {
    if (str[c] == chr) cnt++;
    c++;
    }
    return cnt;
    }

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }

    I'd usually see whether the initialization could also be placed in
    the loop; I dislike those "incomplete" "C" loops. Or I'd have used
    a 'while' loop which I consider to be clearer

    while (*str != '\0')
    count += (*str++ == match);

    I'd probably even omitted the comparison and relied on the implicit
    non-0 (*str) test. (I don't recall that this is a problem, or is it?)

    That's at least what I'd call even a bit more idiomatic, reducing the expressions to that extent.

    Janis

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Sat Apr 11 08:59:31 2026
    From Newsgroup: comp.lang.c

    On 2026-04-08 23:13, DFS wrote:
    [...]

    And I notice I didn't specify the output format.  I want it to look like this:

    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mordant
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping

    Since you asked in another post; then it would be (with Unix tools on
    the command-line) just a single 'sed' to make the data line-canonical
    for the sort-processing

    sed 's/, /\n/g' | sort -k2 -k1

    (so just 30 characters, compared to the 60 with a re-lining-up 'sed').

    Janis

    [...]

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Sat Apr 11 09:34:26 2026
    From Newsgroup: comp.lang.c

    On 2026-04-11 08:59, Janis Papanagnou wrote:
    On 2026-04-08 23:13, DFS wrote:
    [...]

    And I notice I didn't specify the output format.  I want it to look
    like this:

    BTW; you also didn't specify what to do with words that don't have
    two name components.

    I noticed, besides the already mentioned Greek entry ("Άρης Δάσος") a couple single word entries (darrin, Mordant, ReallyBored, taishi28012).
    What to do with those?

    Mind that for a sensible data processing you'd fix input data before
    doing the processing. (Otherwise you'd get trash-in trash-out quality,
    and/or bulky/unmaintainable programs to "fix" data issues on the fly.)

    Janis

    [...]

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Sat Apr 11 08:49:11 2026
    From Newsgroup: comp.lang.c

    cross@spitfire.i.gajendra.net (Dan Cross) writes:

    In article <20260409025901.00002bc6@yahoo.com>,
    Michael S <already5chosen@yahoo.com> wrote:

    On Wed, 08 Apr 2026 23:35:35 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    [snip]

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }

    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.

    Which is irrelevant in this specific case.
    BTW, I think that (ptr != 0) is guaranteed to work even on systems
    with null pointers not being numerically zero. But I am not
    certain about it. What I am certain is that on the right side of
    assignment to pointer 0 always acts the same as NULL.
    But that's too irrelevant for our case.

    It's easy enough to verify looking at a canonical source.
    Section 6.3.2.3 coupled with 6.5.9 of C18 suggest this is
    guaranteed to work.

    As to being pedantic w.r.t. '\0', may be you acquired this habit
    because of C++? If I am not mistaken, in C++ '\0' has type char
    and due to that (or because of, which is IMHO, more appropriate
    wording) can in some contexts lead to results different from 0,
    with differences as huge as call to completely different procedure.
    It does not happen in C where we have no misfeature of type based
    static polymorphism.

    '\0' is indeed a `char` in C++. But I don't think that really
    changes the point, which is more about semantics. Why NOT use a
    relevant character constant instead of `0`? It's not whether
    one can or not, or whether it's semantically equivalent, or
    whether C's `char` type is really an integer in a trenchcoat:
    it's using the appropriate constant to match the domain: in this
    case, matching character data.

    There's no reason to use a constant at all; just write '*str'.
    This writing isn't just idiomatic -- it's integral to how the
    language was designed, not only for string termination but also
    the rules for null pointers and how expressions work in the
    context of for(), if(), and while(). Writing != 0 or != '\0' is
    a holdover from being used to writing Pascal (or any number of
    other earlier languages). When in Rome, do as the Romans do.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Sort@Sort@invalid.invalid to comp.lang.c on Sat Apr 11 19:15:05 2026
    From Newsgroup: comp.lang.c

    On 08/04/2026 04:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George
    Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten,
    Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang,
    Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens
    Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang,
    Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip
    Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal
    Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.


    I would start with something simple and improve on it:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    // Function to extract last name from full name
    const char* get_last_name(const char* full_name) {
    const char* last_space = strrchr(full_name, ' ');
    if (last_space == NULL) {
    return full_name;       // No space → whole string is last name
    }
    return last_space + 1;      // Return pointer after last space
    }

    // Comparison function for qsort (sorts by last name)
    int compare_by_last_name(const void* a, const void* b) {
    const char* name1 = *(const char**)a;
    const char* name2 = *(const char**)b;

    const char* last1 = get_last_name(name1);
    const char* last2 = get_last_name(name2);

    return strcmp(last1, last2);
    }

    int main() {
    // Array of names
    char* names[] = {
    "Martin Hohenberg", "Jae Yang","Tim Bando","Daniel Garber","Kyle Burkholder","Mike
    Nichols","Mark Ping","Tom Taylor","Arnold F. Williams","George Brower","Michael Nygard","Brendan Long","Sven Dowideit","Dave Witten","Jonathan Cast","James Cronin","David L. Jessup","Christopher Chang","Killer Delicious","Jacob Lyles","Neil
    Anuskiewicz","Mordant","Clemens Ladisch","Wojciech Woytniak","Masa Bando","John Carmack","Xingyu Wang","Jane Tang","Steven Evans","Jan Roudaut","Hsueh Sung","Ken LaCrosse","taishi28012","John Simpson","Jerod Tufte","Paul Abbott","Stan Witherspoon","Donald Greer","Gratiela Chergu","Michael Ciagala","Dale Carstensen","Chip Davis","Liudmilla Karukina","Jim McCloskey","Dewey Sasser","Hal Hildebrand","Connor
    Wood","Ken Kennedy","darrin","Mark Gardner","William
    Christensen","Malcolm Ocean","Rod Davenport","Nodarius Darjania","Cheryl Evry","Wenfeng Liang","Irving Rivas","Bill Soistman","ReallyBored","???? ?????","Ron Lauzon","TheFred", "Paul Theodoropolous","Doug
    Phillips","Les Vogel","Matt Pollard","Andres Cordova"
    };

    int n = sizeof(names) / sizeof(names[0]);

    printf("Before sorting:\n");
    for (int i = 0; i < n; i++) {
    printf("%s\n", names[i]);
    }

    // Sort using qsort
    qsort(names, n, sizeof(char*), compare_by_last_name);

    printf("\nAfter sorting by last name:\n");
    for (int i = 0; i < n; i++) {
    printf("%s\n", names[i]);
    }

    return 0;
    }

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.lang.c on Sat Apr 11 19:59:39 2026
    From Newsgroup: comp.lang.c

    In article <86eckla45k.fsf@linuxsc.com>,
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
    cross@spitfire.i.gajendra.net (Dan Cross) writes:

    In article <20260409025901.00002bc6@yahoo.com>,
    Michael S <already5chosen@yahoo.com> wrote:

    On Wed, 08 Apr 2026 23:35:35 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Wed, 08 Apr 2026 21:04:56 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:

    [snip]

    Idiomatically, I might have written

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0u;
    for(; *str != '\0'; str++) count += (*str == match);
    return count;
    }

    I'd change it to

    size_t
    countchar(const char *str, char match)
    {
    size_t count = 0;
    for(; *str != 0; str++) count += (*str == match);
    return count;
    }

    Personally, I prefer to properly identify integer constants
    with the appropriate type annotation. I always explicitly
    check against NULL rather than using !ptr, for example. I
    never use an unadorned integer for a character constant,
    rather using either 'c' for printables, the legal escapes
    (e.g. \n) and for any non-printable, the appropriate
    octal escape.

    Perhaps some of this is pedantic. I worked with a system
    where the null pointer constant was not the value zero, so
    I'm aware that !ptr may not actually do the right thing in
    such cases.

    Which is irrelevant in this specific case.
    BTW, I think that (ptr != 0) is guaranteed to work even on systems
    with null pointers not being numerically zero. But I am not
    certain about it. What I am certain is that on the right side of
    assignment to pointer 0 always acts the same as NULL.
    But that's too irrelevant for our case.

    It's easy enough to verify looking at a canonical source.
    Section 6.3.2.3 coupled with 6.5.9 of C18 suggest this is
    guaranteed to work.

    As to being pedantic w.r.t. '\0', may be you acquired this habit
    because of C++? If I am not mistaken, in C++ '\0' has type char
    and due to that (or because of, which is IMHO, more appropriate
    wording) can in some contexts lead to results different from 0,
    with differences as huge as call to completely different procedure.
    It does not happen in C where we have no misfeature of type based
    static polymorphism.

    '\0' is indeed a `char` in C++. But I don't think that really
    changes the point, which is more about semantics. Why NOT use a
    relevant character constant instead of `0`? It's not whether
    one can or not, or whether it's semantically equivalent, or
    whether C's `char` type is really an integer in a trenchcoat:
    it's using the appropriate constant to match the domain: in this
    case, matching character data.

    There's no reason to use a constant at all; just write '*str'.
    This writing isn't just idiomatic -- it's integral to how the
    language was designed, not only for string termination but also
    the rules for null pointers and how expressions work in the
    context of for(), if(), and while(). Writing != 0 or != '\0' is
    a holdover from being used to writing Pascal (or any number of
    other earlier languages).

    This is subjective, and _a_ response from a different school of
    thought may be that `*str` is not a boolean type, and thus
    should not be used in a boolean context. You may disagree; I
    may occasionally disagree myself, but again, it's subjective.

    When in Rome, do as the Romans do.

    This is the critical part. Many Unix and Unix-like kernels, for
    instance, have style guides that demand comparison against an
    appropriately type constants, along with other style rules about
    the placement of braces, use of whitespace, indentation, and so
    on. If one works in those kernels, one doesn't really have a
    lot of choice: one must do what the Romans in that instance of
    Rome do, regardless of personal preference.

    - Dan C.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Sun Apr 12 06:35:01 2026
    From Newsgroup: comp.lang.c

    scott@slp53.sl.home (Scott Lurndal) writes:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.

    Any C implementation where !ptr does the wrong thing almost certainly
    does not exist. It's difficult to imagine that a C compiler with
    such a fundamental bug would ever go out the door.

    It's barely possible that compiler that uses a representation other
    than all-bits-zero for null pointers might have such a bug, but
    (a) anyone creating such an implementation will almost certainly
    be extremely careful to get such things right, and (b) I'm not sure
    that any such compilers even exist, except perhaps for old systems
    that would be considered exotic today.

    Or even obsolete. The systems in question were all retired by
    2010, and never had a C compiler. The system was BCD and the
    six digit 'undigit' value of EEEEEE was chosen as the NIL (NULL)
    pointer value.

    It would be nice if in the future it were stated directly when a
    non-C environment is the context of a comment. I mistakenly
    understood that what you were saying had to do with experience
    using some unusual C compiler.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Sun Apr 12 06:48:19 2026
    From Newsgroup: comp.lang.c

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.

    Any C implementation where !ptr does the wrong thing almost certainly
    does not exist. It's difficult to imagine that a C compiler with
    such a fundamental bug would ever go out the door.

    My usual preference is to draw conclusions based on evidence rather
    imagination or supposition.

    It's barely possible that compiler that uses a representation other
    than all-bits-zero for null pointers might have such a bug, but
    (a) anyone creating such an implementation will almost certainly
    be extremely careful to get such things right, and (b) I'm not sure
    that any such compilers even exist, except perhaps for old systems
    that would be considered exotic today.

    Here again this sounds like just supposition. How much experience
    do you have, and how extensive, using non-mainstream C compilers?
    For myself I can't say I much at all, but I have seen one where
    believe it or not assert() was implemented wrongly. assert()! I
    certainly wouldn't have guessed that before actually seeing it.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.lang.c on Sun Apr 12 14:51:46 2026
    From Newsgroup: comp.lang.c

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:


    Or even obsolete. The systems in question were all retired by
    2010, and never had a C compiler. The system was BCD and the
    six digit 'undigit' value of EEEEEE was chosen as the NIL (NULL)
    pointer value.

    It would be nice if in the future it were stated directly when a
    non-C environment is the context of a comment. I mistakenly
    understood that what you were saying had to do with experience
    using some unusual C compiler.

    I was in the OS group at the time. The languages group had
    started looking at writing a C compiler for the architecture, but
    it never panned out (and there was little interest from the
    predominantly COBOL customer base).
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From BGB@cr88192@gmail.com to comp.lang.c on Sun Apr 12 13:08:41 2026
    From Newsgroup: comp.lang.c

    On 4/8/2026 3:22 AM, Janis Papanagnou wrote:
    On 2026-04-08 05:14, DFS wrote:
    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George
    Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten,
    Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang,
    Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens
    Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang,
    Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon,
    Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip
    Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal
    Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William
    Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης
    Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les
    Vogel, Matt Pollard, Andres Cordova


    Print first last [name] (as shown above) but ordered by last first.

    In cases like this where data with Latin and Greek characters are
    mixed you should clarify or even define how the comparison function
    shall operate on mixed data to create a "correct" ordering.

    Hereabouts we usually insert the "Άρης Δάσος" (starting with the letter Delta) before or after the letter 'D'; i.e. using an implicit transcription. But this may not suit other cases. Or artificial ones
    like this challenge, so you should probably clarify for folks who
    are interested to re-implement (or use) a sorting function in "C"
    (with or without a locale setting to do the dirty work).


    FWIW...


    One approach I had defined for some filesystem code of mine:
    Normalize encoding as UTF-8 or similar;
    Do a byte-for-byte comparison of the UTF-8 strings.

    UTF-8 normalization can itself get complicated.
    Though, keeping the set of rules minimal can help;
    Otherwise, the task can become unreasonable.


    Otherwise, the normalization and collation rules were assumed to be independent of locale.

    Well, and tend not to be collation-correct even for US ASCII (where,
    say, people often expect alphabetic ordering and letters to come first,
    unlike ASCII ordering where numbers come first, then upper case, then
    lower case, with various symbols between them, ...).



    For storage, there were a few options:
    Option 1:
    Leave everything as UTF-8, using only UTF-8;
    Option 2:
    Allow CP1252 if name string could be represented exactly;
    And, the 1252 would not be confused for valid UTF-8.


    The merit of 2 is that, besides purely ASCII filenames, CP1252 names
    were a solid second place in my states, followed in the 3rd place by
    names with emojis, and 4th place by Chinese characters and similar, ...

    Granted, person names are different from filenames so would likely have
    a different ranking (well, and you can hope people don't start naming
    kids with names containing emojis, ...).

    Though, can note that the reasoning in this case was that there was a short-name case (names that fit under a 48-byte limit), and long-name
    case (names that exceeded 48 bytes), and the difference between 1252 and
    UTF-8 could often be "make or break" for a name fitting within the 48
    byte limit (without the complexity of full code-page handling).

    Though, in this case, if 1252 was used, one could end up with it doing byte-for-byte comparison between UTF-8 and 1252, but this was OK (well,
    and for purposes of sorting, it only cared about the short-name field,
    which for long names would contain the first 40 bytes with the last 8
    bytes replaced with a hash of the full length name).


    In this case, name hash algorithm was defined as, roughly:
    uint64_t DfsLongNameHash(char *name)
    {
    uint64_t h0, h1, h;
    char *s;
    int i, c, l, n;

    l=strlen(name);
    s=name; h0=1; h1=0;
    n=l>>2;
    for(i=0; i<n; i++)
    { h1+=h0; h0+=*(uint32_t *)s; s+=4; }
    if(n&3)
    {
    c=*(uint32_t *)s;
    c&=((1U<<((n&3)*8))-1);
    h1+=h0; h0+=c;
    }
    h0=((uint32_t)h0)+(h0>>32); h1=((uint32_t)h1)+(h1>>32);
    h0=((uint32_t)h0)+(h0>>32); h1=((uint32_t)h1)+(h1>>32);
    h=h0|(h1<<32);
    return(h);
    }

    ...


    Hasn't seen that much practical use thus far.
    Initially it was motivated by:
    FAT is kinda limited,
    and faking a Unix-style FS on top of FAT is lame.
    NTFS was way too needlessly complicated.
    EXT2 almost works, but:
    Has some needless design cruft that was better handled in NTFS;
    General approach makes sense though.
    Handling of directories would be needlessly inefficient.
    Linear search over variable-sized dirents.


    So, ended up with a design partway between NTFS and EXT2, but aiming to
    avoid needless complexity and to keep the design reasonably efficient.
    Inode table: Hybrid approach,
    inode-table is self-defining like the MFT.
    Block management strategy superficially similar to EXT2.
    Though, using a single global bitmap, rather than block groups;
    Bitmap and inode table can grow as needed, ...
    Directories used fixed-size dirents organized into an AVL tree.
    In this case, was chosen as a compromise.
    Linear directories are simpler, but scale poorly.
    AVL trees were intermediate between linear and B-Trees.
    Efficiency analysis favored AVL trees in this case.

    Though, the pain of rebalancing trees on insert/delete left me
    questioning the choice. Because delete was too much of a pain, ended up
    using a strategy where it would mark nodes as deleted and then (as
    convenient) actually remove the entries in subsequent node rotates (and
    also making the re-balancing more lax as I had noted that +/- 2 would
    result in significantly less rotates than +/- 1).

    As, dealing with directory insert/delete handling became one of the more complicated parts of the filesystem.

    Over the range of typical directory sizes, AVL trees remained as the
    more efficient option, only getting edged out by B-Trees for excessively
    large directories (but nearly always having a cheaper lookup cost vs
    linear search, even if insert/delete costs are often higher).

    ...


    Though, can note that with such an approach, something seemingly minor
    like a change in normalization or collation behavior could break the
    ability of the FS driver to open files. Which is a possible area for
    concern.


    Though, for NTFS, the strategy had been to ship things like the
    code-point collation ordering tables along with the filesystem
    (theoretically, could depend on the locale the FS was formatted under;
    AFAIK in practice a global set of tables was used independent of
    locale). Better IMO to keep collation as part of a UI-presentation thing (whether the file browser presents files ordered in a way that makes
    sense for the user's locale being a locale-specific thing).


    Was simplified slightly by assuming everything is case-sensitive.
    Actually, I went a little non-standard by even having the FAT driver as
    case sensitive.

    ...


    ------------------------------------------------------------------
    No peeking!
    [...removed without peeking...]
    71 SLOC
    No necessity for peeking since I'd write a Unix 'sort' one-liner
    (instead of a bulky "C" program). ;-)

    Honestly; mind to explain what the point of this "C" challenge is?

    (From the application user's perspective the most interesting thing
    would be a sophisticated handling of "mixed locales", but I assume
    you're just using what C's 'str*cmp' functions technically provide
    with whatever environment setting, and the challenge is something
    else?)


    Yeah, mostly agreed here.


    Janis


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c on Sun Apr 12 16:15:46 2026
    From Newsgroup: comp.lang.c

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    The semantics of !ptr has been codified to mean 1 for null pointers
    since the original C standard. Heck, even during the 1970s when C
    allowed assigning integers directly to pointers, K&R said that
    assigning 0 to a pointer produces a pointer guaranteed to be
    different than a pointer to any object. Any C implementation where
    !ptr does the wrong thing should be avoided like the plague.

    Any C implementation where !ptr does the wrong thing almost certainly
    does not exist. It's difficult to imagine that a C compiler with
    such a fundamental bug would ever go out the door.

    My usual preference is to draw conclusions based on evidence rather imagination or supposition.

    Good for you.

    It's barely possible that compiler that uses a representation other
    than all-bits-zero for null pointers might have such a bug, but
    (a) anyone creating such an implementation will almost certainly
    be extremely careful to get such things right, and (b) I'm not sure
    that any such compilers even exist, except perhaps for old systems
    that would be considered exotic today.

    Here again this sounds like just supposition. How much experience
    do you have, and how extensive, using non-mainstream C compilers?
    For myself I can't say I much at all, but I have seen one where
    believe it or not assert() was implemented wrongly. assert()! I
    certainly wouldn't have guessed that before actually seeing it.

    Quick summary: You wrote that "Any C implementation where !ptr does
    the wrong thing should be avoided like the plague." My response
    was, to summarize briefly, that such implementations are unlikely
    to exist and not worth worrying about.

    Do you disagree, or are you just criticizing the way I said it?
    I believe I was clear about the basis for my statement. No, I don't
    have a lot of experience with non-mainstream C compilers. I'm not
    going to perform a survey of all historical C implementations.

    Do you have anything useful to say about my point, as opposed to
    how I expressed it?

    I speculate that no released C implementation gets either !ptr or
    2+2 wrong. A bug in the former is, I speculate, more likely than a
    bug in the latter, but neither seems likely. If such a bug exists,
    my guess is that it's in a pre-standard compiler for some system
    that is now obsolete. K&R1 (1978) is less than clear about the
    representation of null pointers.

    Would you be surprised to see a C compiler that handles !ptr
    incorrectly?

    I'd be interested in more information about the implementation
    that implemented assert() incorrectly.
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Mon Apr 13 06:31:00 2026
    From Newsgroup: comp.lang.c

    scott@slp53.sl.home (Scott Lurndal) writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    scott@slp53.sl.home (Scott Lurndal) writes:

    Or even obsolete. The systems in question were all retired by
    2010, and never had a C compiler. The system was BCD and the
    six digit 'undigit' value of EEEEEE was chosen as the NIL (NULL)
    pointer value.

    It would be nice if in the future it were stated directly when a
    non-C environment is the context of a comment. I mistakenly
    understood that what you were saying had to do with experience
    using some unusual C compiler.

    I was in the OS group at the time. The languages group had
    started looking at writing a C compiler for the architecture, but
    it never panned out (and there was little interest from the
    predominantly COBOL customer base).

    I'm sure there was a good reason for working in the development
    environment you were using, and I didn't mean to imply otherwise.
    I just wanted a heads-up about the non-C-ness of it.
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Thu Apr 16 18:24:58 2026
    From Newsgroup: comp.lang.c

    As usual - in a superior language.

    #include <iostream>
    #include <utility>
    #include <string_view>
    #include <regex>
    #include <vector>
    #include <algorithm>

    using namespace std;

    static constexpr string_view Names = "Martin Hohenberg, Jae Yang, Tim
    Bando, Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom
    Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long,
    Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L.
    Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil
    Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando,
    John Carmack, Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh
    Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott,
    Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser,
    Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova";

    int main()
    {
    regex
    rxComma( "\\s*([^,]+)(,|$)" ),
    rxRvSurname( "\\s*(\\S+)" ),
    rxGapSpaces( "(\\s+)" );
    match_results<string_view::iterator> mtch;
    match_results<string_view::reverse_iterator> reverseMatch;
    using name = pair<string_view, string_view>;
    vector<name> names;
    for( auto itName = ::Names.begin(); ; itName = mtch[0].second )
    {
    if( !regex_search( itName, ::Names.end(), mtch, rxComma ) )
    break;
    if( !regex_search( reverse_iterator( mtch[1].second ), reverse_iterator( mtch[1].first ), reverseMatch, rxRvSurname ) )
    continue;
    auto
    itSurname = reverseMatch[1].second.base(),
    itSurnameEnd = reverseMatch[1].first.base();
    string_view surname( itSurname, itSurnameEnd );
    auto itForename = mtch[1].first;
    if( !regex_search( reverse_iterator( itSurname ), reverse_iterator(
    itForename ), reverseMatch, rxGapSpaces ) )
    continue;
    auto itForenameEnd = reverseMatch[1].second.base();
    string_view forename( itForename, itForenameEnd );
    names.emplace_back( forename, surname );
    }
    sort( names.begin(), names.end(), []( const name &lhs, const name &rhs ) { return lhs.second < rhs.second; } );
    for( const name &nm : names )
    {
    cout << "\"" << nm.first << "\" - \"" << nm.second << "\"" << endl;
    }
    }

    The cool thing about that that I'm matching a part of the name with
    a reverse-iterator, i.e. I do reverse regex parsing (the regex itself
    is forward).

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Thu Apr 16 18:50:11 2026
    From Newsgroup: comp.lang.c

    Am 09.04.2026 um 01:59 schrieb Michael S:

    BTW, I think that (ptr != 0) is guaranteed to work even on systems with
    null pointers not being numerically zero. ...

    Sorry, that's ridiculous. Which system ever has used sth. different than
    a physical null-pointer for a logical. And do you really expect that to
    happen in the future ?
    You see uncertainties where ther are non.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bart@bc@freeuk.com to comp.lang.c on Thu Apr 16 18:38:46 2026
    From Newsgroup: comp.lang.c

    On 16/04/2026 17:24, Bonita Montero wrote:
    As usual - in a superior language.

    #include <iostream>
    #include <utility>
    #include <string_view>
    #include <regex>
    #include <vector>
    #include <algorithm>

    using namespace std;

    static constexpr string_view Names = "Martin Hohenberg, Jae Yang, Tim
    Bando, Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom
    Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L.
    Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil
    Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando,
    John Carmack, Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh
    Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser,
    Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova";

    int main()
    {
        regex
            rxComma( "\\s*([^,]+)(,|$)" ),
            rxRvSurname( "\\s*(\\S+)" ),
            rxGapSpaces( "(\\s+)" );
        match_results<string_view::iterator> mtch;
        match_results<string_view::reverse_iterator> reverseMatch;
        using name = pair<string_view, string_view>;
        vector<name> names;
        for( auto itName = ::Names.begin(); ; itName = mtch[0].second )
        {
            if( !regex_search( itName, ::Names.end(), mtch, rxComma ) )
                break;
            if( !regex_search( reverse_iterator( mtch[1].second ), reverse_iterator( mtch[1].first ), reverseMatch, rxRvSurname ) )
                continue;
            auto
                itSurname = reverseMatch[1].second.base(),
                itSurnameEnd = reverseMatch[1].first.base();
            string_view surname( itSurname, itSurnameEnd );
            auto itForename = mtch[1].first;
            if( !regex_search( reverse_iterator( itSurname ), reverse_iterator( itForename ), reverseMatch, rxGapSpaces ) )
                continue;
            auto itForenameEnd = reverseMatch[1].second.base();
            string_view forename( itForename, itForenameEnd );
            names.emplace_back( forename, surname );
        }
        sort( names.begin(), names.end(), []( const name &lhs, const name &rhs ) { return lhs.second < rhs.second; } );
        for( const name &nm : names )
        {
            cout << "\"" << nm.first << "\" - \"" << nm.second << "\"" <<
    endl;
        }
    }

    The cool thing about that that I'm matching a part of the name with
    a reverse-iterator, i.e. I do reverse regex parsing (the regex itself
    is forward).


    What's not cool is that it takes 4.7 seconds to compile this 45 line
    program, unoptimised. and 7.7 seconds optimised.

    Does it need to be optimised? I guess so, even if it's just to get the
    size down: optimised is 136KB, unoptimised it's 319KB.

    Tiny C builds the C version in pretty much zero seconds, for a 8KB program.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Thu Apr 16 19:43:47 2026
    From Newsgroup: comp.lang.c

    Am 16.04.2026 um 19:38 schrieb Bart:

    What's not cool is that it takes 4.7 seconds to compile this 45 line program, unoptimised. and 7.7 seconds optimised.

    Doesn't matter if you need not a third of the time to develop the code.
    And if you like more performance you can use C++20 modules.

    Does it need to be optimised? I guess so, even if it's just to get the
    size down: optimised is 136KB, unoptimised it's 319KB.

    Doesn't matter.

    Tiny C builds the C version in pretty much zero seconds, for a 8KB program.

    Is this really an advantage ? You C guys really suck.
    You continue to see details without noting the overall picture.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.lang.c on Thu Apr 16 19:54:58 2026
    From Newsgroup: comp.lang.c

    In article <10rr402$1r3mi$1@raubtier-asyl.eternal-september.org>,
    Bonita Montero <Bonita.Montero@gmail.com> wrote:
    Am 09.04.2026 um 01:59 schrieb Michael S:

    BTW, I think that (ptr != 0) is guaranteed to work even on systems with
    null pointers not being numerically zero. ...

    Sorry, that's ridiculous. Which system ever has used sth. different than
    a physical null-pointer for a logical. And do you really expect that to >happen in the future ?
    You see uncertainties where ther are non.

    Hmm, I wonder if the AS/400 has this.

    - Dan C.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Fri Apr 17 16:22:40 2026
    From Newsgroup: comp.lang.c

    Am 16.04.2026 um 21:54 schrieb Dan Cross:

    In article <10rr402$1r3mi$1@raubtier-asyl.eternal-september.org>,

    Bonita Montero <Bonita.Montero@gmail.com> wrote:

    Sorry, that's ridiculous. Which system ever has used sth. different than
    a physical null-pointer for a logical. And do you really expect that to
    happen in the future ?
    You see uncertainties where ther are non.

    Hmm, I wonder if the AS/400 has this.

    With the AS/400 the NULL-pointer is physically zero. But the AS/400
    has typed registers so that a NULL-pointer is sth. different than a
    register with an zero integer.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.lang.c on Fri Apr 17 20:44:03 2026
    From Newsgroup: comp.lang.c

    In article <10r537m$in2o$4@dont-email.me>,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    ...
    Honestly; mind to explain what the point of this "C" challenge is?

    To generate traffic on an otherwise sterile and (almost) dead newsgroup on
    an (almost) dead platform.

    It (and, more generally, its author) has done an admirable job of that.

    Or, to put it another way, what is the point of comp.lang.c?

    Answer that, and you will be most of the way to answering the original question.
    --
    I've been watching cat videos on YouTube. More content and closer to
    the truth than anything on Fox.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Rosario19@Ros@invalid.invalid to comp.lang.c on Sat Apr 18 11:16:48 2026
    From Newsgroup: comp.lang.c

    On Tue, 7 Apr 2026 23:14:41 -0400, DFS wrote:

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, >Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, >James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson, >Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken >Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod >Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, ???? ?????, Ron Lauzon, TheFred, Paul >Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.
    ot

    this would be one APL program in "brace" form and its result, because
    here it seems is difficult print 2 chars chars

    s{leftarrow}{apostrophe}Martin Hohenberg, Jae Yang, Tim Bando,
    Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor,
    Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven
    Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz,
    Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack,
    Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken
    LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale
    Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey
    Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark
    Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius
    Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas, Bill Soistman,
    ReallyBored, {\x00CE}{\x2020}{\x00CF}{\x0081}{\x00CE}{\x00B7}
    {\x00CF}{\x201A}
    {\x00CE}{\x201D}{\x00CE}{\x00AC}{\x00CF}{\x0192}{\x00CE} {\x00BF}{\x00CF}{\x201A}, Ron Lauzon, TheFred, Paul Theodoropolous,
    Doug Phillips, Les Vogel, Matt Pollard, Andres
    Cordova{apostrophe}{cr}{lf}

    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}{leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}{leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}

    Mordant
    taishi28012
    darrin
    ReallyBored
    TheFred
    Paul Abbott
    Neil Anuskiewicz
    Tim Bando
    Masa Bando
    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry
    Arnold F. Williams
    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    Liudmilla Karukina
    Ken Kennedy
    David L. Jessup
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From gggggggggggunit@gunitinug@50cent.com to comp.lang.c on Sat Apr 18 10:19:41 2026
    From Newsgroup: comp.lang.c

    $ cat names.txt | tr -d '\n' | sed 's/,/\n/g' | sed 's/^ //g' | awk 'NF ==
    3 { print $1, $3, $2 } NF == 2 { print $1, $2 } NF ==1 { print $1 }' |
    sort -k 2,2 -k 1,1 | awk 'NF == 3 { print $1, $3, $2 } NF == 2 { print
    $1, $2 } NF ==1 { print $1 }'
    darrin
    Mordant
    ReallyBored
    taishi28012
    TheFred
    Paul Abbott
    Neil Anuskiewicz
    Masa Bando
    Tim Bando
    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry
    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    David L. Jessup
    Liudmilla Karukina
    Ken Kennedy
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Arnold F. Williams
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang
    Άρης Δάσος


    On Tue, 7 Apr 2026 23:14:41 -0400, DFS wrote:

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.















































































    ------------------------------------------------------------------
    No peeking! ------------------------------------------------------------------
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char names[2000] = {"Martin Hohenberg, Jae Yang, Tim Bando, Daniel
    Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit,
    Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher
    Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane
    Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012,
    John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres
    Cordova"};


    //count characters in a string int countchr(char *str, char chr)
    {int c=0,cnt=0;while(str[c]!='\0'){if(str[c]==chr){cnt++;}c++;}return
    cnt;}

    //compare for qsort int comparechar( const void *a, const void *b)
    {
    const char **chara = (const char **)a;
    const char **charb = (const char **)b;
    return strcasecmp(*chara, *charb);
    //return strcmp(*chara, *charb);
    }


    //left trim spaces void ltrim(char *str)
    {
    int totrim = strspn(str," ");
    if (totrim > 0)
    {
    int len = strlen(str);
    if (totrim == len)
    { str[0] = '\0'; } else
    {memmove(str, str + totrim, len + 1 - totrim);}
    }
    }


    int main(void)
    {

    //vars
    char delim[2] = ",";
    int i=0,j=0;

    //number of names is commas + 1 int namecnt = countchr(names,',')
    + 1;

    //name array: one column for first-last, one for last-first char
    *narr[2][namecnt];

    char *flname, lfname[30]; // full names char *fname,
    *lname; //
    part names char tmp[30]="";

    // parse full names from string // then parse first and last from
    full
    name // add both into array char *dup = strdup(names);
    while((flname = strsep(&dup,delim)) != NULL )
    {
    ltrim(flname);
    if(countchr(flname,' ')>0)
    {
    lname = strrchr(flname,' ')+1;
    memset(tmp, '\0', sizeof(tmp));
    strncat(tmp,flname,strlen(flname)-
    strlen(lname)-1);
    fname = strdup(tmp);
    }
    else {
    lname = strdup(flname);
    fname = strdup("");
    fname[strlen(fname)-2] = '\0';
    }

    sprintf(lfname,"%s %s",lname,fname); narr[0][i]=
    strdup(flname);
    narr[1][i]= strdup(lfname);
    i++;
    }


    //add list of last-first names into array then sort it char
    *sarr[namecnt];
    for(i=0;i<namecnt;i++) {sarr[i] = narr[1][i];}
    qsort(sarr, namecnt, sizeof(char*), comparechar);

    //print first-last in order by last-first for(i=0;i<namecnt;i++)
    {
    for(j=0;j<namecnt;j++)
    {
    if(narr[1][j] == sarr[i])
    {
    printf("%d %s\n",i+1, narr[0][j]);
    break;
    }
    }
    }

    return 0;
    }
    ------------------------------------------------------------------
    71 SLOC

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bart@bc@freeuk.com to comp.lang.c on Sat Apr 18 11:22:27 2026
    From Newsgroup: comp.lang.c

    On 16/04/2026 17:24, Bonita Montero wrote:

        sort( names.begin(), names.end(), []( const name &lhs, const name &rhs ) { return lhs.second < rhs.second; } );


    I think this needs to be a case-insensitive sort.

    While the OP's data only had capitalised surnames (with one exception),
    their solution used a string-sensitive compare.

    The exception is the name "taishi28012". With your code, that name
    doesn't appear at all in the output.

    If I add a dummy first name to this, then it appears last of all the
    ASCII names, but before the Greek name.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From DFS@nospam@dfs.com to comp.lang.c on Sat Apr 18 08:11:01 2026
    From Newsgroup: comp.lang.c

    On 4/18/2026 5:16 AM, Rosario19 wrote:
    On Tue, 7 Apr 2026 23:14:41 -0400, DFS wrote:

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower,
    Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast,
    James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson,
    Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken
    Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod
    Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, ???? ?????, Ron Lauzon, TheFred, Paul
    Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.
    ot

    this would be one APL program in "brace" form and its result, because
    here it seems is difficult print 2 chars chars

    s{leftarrow}{apostrophe}Martin Hohenberg, Jae Yang, Tim Bando,
    Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor,
    Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz,
    Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack,
    Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken
    LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale
    Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey
    Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark
    Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, {\x00CE}{\x2020}{\x00CF}{\x0081}{\x00CE}{\x00B7} {\x00CF}{\x201A}
    {\x00CE}{\x201D}{\x00CE}{\x00AC}{\x00CF}{\x0192}{\x00CE} {\x00BF}{\x00CF}{\x201A}, Ron Lauzon, TheFred, Paul Theodoropolous,
    Doug Phillips, Les Vogel, Matt Pollard, Andres
    Cordova{apostrophe}{cr}{lf}

    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}{leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}{leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}

    Mordant
    taishi28012
    darrin
    ReallyBored
    TheFred
    Paul Abbott
    Neil Anuskiewicz

    --------------------------------
    Tim Bando
    Masa Bando
    --------------------------------
    FAIL


    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry
    Arnold F. Williams
    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    Liudmilla Karukina
    Ken Kennedy
    David L. Jessup
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bart@bc@freeuk.com to comp.lang.c on Sat Apr 18 14:03:30 2026
    From Newsgroup: comp.lang.c

    On 18/04/2026 13:11, DFS wrote:
    On 4/18/2026 5:16 AM, Rosario19 wrote:
    On Tue, 7 Apr 2026 23:14:41 -0400, DFS  wrote:

    Martin Hohenberg, Jae Yang, Tim Bando, Daniel Garber, Kyle Burkholder,
    Mike Nichols, Mark Ping, Tom Taylor, Arnold F. Williams, George Brower,
    Michael Nygard, Brendan Long, Sven Dowideit, Dave Witten, Jonathan Cast, >>> James Cronin, David L. Jessup, Christopher Chang, Killer Delicious,
    Jacob Lyles, Neil Anuskiewicz, Mordant, Clemens Ladisch, Wojciech
    Woytniak, Masa Bando, John Carmack, Xingyu Wang, Jane Tang, Steven
    Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse, taishi28012, John Simpson, >>> Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald Greer, Gratiela
    Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood, Ken
    Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod
    Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas,
    Bill Soistman, ReallyBored, ???? ?????, Ron Lauzon, TheFred, Paul
    Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova


    Print first last (as shown above) but ordered by last first.
    ot

    this would be one APL program in "brace" form and its result, because
    here it seems is difficult print 2 chars chars

           s{leftarrow}{apostrophe}Martin Hohenberg, Jae Yang, Tim Bando, >> Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor,
    Arnold F. Williams, George Brower, Michael Nygard, Brendan Long, Sven
    Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L. Jessup,
    Christopher Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz,
    Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando, John Carmack,
    Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken
    LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott, Stan
    Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale
    Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey
    Sasser, Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark
    Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius
    Darjania, Cheryl Evry, Wenfeng Liang, Irving Rivas, Bill Soistman,
    ReallyBored, {\x00CE}{\x2020}{\x00CF}{\x0081}{\x00CE}{\x00B7}
    {\x00CF}{\x201A}
    {\x00CE}{\x201D}{\x00CE}{\x00AC}{\x00CF}{\x0192}{\x00CE}
    {\x00BF}{\x00CF}{\x201A}, Ron Lauzon, TheFred, Paul Theodoropolous,
    Doug Phillips, Les Vogel, Matt Pollard, Andres
    Cordova{apostrophe}{cr}{lf}

    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}
    {leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}
    {leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}
    {apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}

       Mordant
       taishi28012
       darrin
       ReallyBored
       TheFred
       Paul Abbott
       Neil Anuskiewicz

    --------------------------------
       Tim Bando
       Masa Bando
    --------------------------------
    FAIL

    So sorting presumably is case-sensitive, and last name first, then first
    names in order?

    You weren't entirely clear in your OP, where it only talks about first
    and last names, but some entries have only one name, and some have three.

    Perhaps some reference output should have been posted (I saw it
    somewhere but can't find in the thread, and don't know if it came from you).

    I posted a version in script code, but mistakenly in the cookie thread,
    when I got the idea that solutions in any language were allowed. That
    one sorted on last name only (but seems to get the Bandos in the right
    order somehow).

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Sat Apr 18 17:48:52 2026
    From Newsgroup: comp.lang.c

    Am 18.04.2026 um 12:22 schrieb Bart:

    I think this needs to be a case-insensitive sort.

    While the OP's data only had capitalised surnames (with one exception), their solution used a string-sensitive compare.

    The exception is the name "taishi28012". With your code, that name
    doesn't appear at all in the output.

    If I add a dummy first name to this, then it appears last of all the
    ASCII names, but before the Greek name.

    Now everything is fine: surnames without forenames are handled and
    the search is case-insensitive.


    #include <iostream>
    #include <utility>
    #include <string_view>
    #include <regex>
    #include <vector>
    #include <algorithm>
    #include <compare>

    using namespace std;

    static constexpr const char *Names = "Martin Hohenberg, Jae Yang, Tim
    Bando, Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom
    Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long,
    Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L.
    Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil
    Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando,
    John Carmack, Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh
    Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott,
    Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser,
    Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova";

    int svicmp( string_view lhs, string_view rhs );

    int main()
    {
    string_view svNames = ::Names;
    regex
    rxTotal( "\\s*([^,]+)(?:,|$)" ),
    rxRvSurname( "\\s*(\\S+)" ),
    rxRvGap( "\\s+" );
    match_results<string_view::iterator> totalMtch;
    match_results<string_view::reverse_iterator> rvMatch;
    struct name { string_view forename, surname; };
    vector<name> names;
    for( auto itName = svNames.begin(); regex_search( itName, svNames.end(), totalMtch, rxTotal ); itName = totalMtch[0].second )
    {
    if( !regex_search( reverse_iterator( totalMtch[1].second ), reverse_iterator( totalMtch[1].first ), rvMatch, rxRvSurname ) )
    continue;
    auto
    itForename = totalMtch[1].first,
    itSurname = rvMatch[1].second.base(),
    itSurnameEnd = rvMatch[1].first.base();
    string_view surname( itSurname, itSurnameEnd ), forename;
    if( regex_search( reverse_iterator( itSurname ), reverse_iterator(
    itForename ), rvMatch, rxRvGap ) )
    forename = string_view( itForename, rvMatch[0].second.base() );
    else
    if( itSurname != itForename )
    continue;
    names.emplace_back( forename, surname );
    }
    sort( names.begin(), names.end(), []( const name &lhs, const name &rhs )
    {
    int cmpSurname = svicmp( lhs.surname, rhs.surname );
    if( cmpSurname != 0 )
    return cmpSurname < 0;
    return lhs.forename < rhs.forename;
    } );
    for( const name &nm : names )
    cout << "\"" << nm.surname << "\", \"" << nm.forename << "\"" << endl;
    }

    int svicmp( string_view lhs, string_view rhs )
    {
    constexpr auto *lwtoi = +[]( char c ) -> int { return (unsigned char)tolower( c ); };
    size_t c = min( lhs.size(), rhs.size() );
    for( size_t i = 0; i < c; ++i )
    if( int d = lwtoi( lhs[i] ) - lwtoi( rhs[i] ); d )
    return d;
    return lhs.size() < rhs.size();
    }


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Sun Apr 19 08:44:26 2026
    From Newsgroup: comp.lang.c

    Now I've extracted the parsing part in a separate lambda. You cann
    call it with pars( true_type() ) if you wnat regex-parsing. You can
    call it with parse( false_type() ) if you want manual parsing (faster).

    #include <iostream>
    #include <utility>
    #include <string_view>
    #include <regex>
    #include <vector>
    #include <algorithm>
    #include <compare>

    using namespace std;

    static constexpr const char *Names = "Martin Hohenberg, Jae Yang, Tim
    Bando, Daniel Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom
    Taylor, Arnold F. Williams, George Brower, Michael Nygard, Brendan Long,
    Sven Dowideit, Dave Witten, Jonathan Cast, James Cronin, David L.
    Jessup, Christopher Chang, Killer Delicious, Jacob Lyles, Neil
    Anuskiewicz, Mordant, Clemens Ladisch, Wojciech Woytniak, Masa Bando,
    John Carmack, Xingyu Wang, Jane Tang, Steven Evans, Jan Roudaut, Hsueh
    Sung, Ken LaCrosse, taishi28012, John Simpson, Jerod Tufte, Paul Abbott,
    Stan Witherspoon, Donald Greer, Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis, Liudmilla Karukina, Jim McCloskey, Dewey Sasser,
    Hal Hildebrand, Connor Wood, Ken Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod Davenport, Nodarius Darjania, Cheryl
    Evry, Wenfeng Liang, Irving Rivas, Bill Soistman, ReallyBored, Άρης Δάσος, Ron Lauzon, TheFred, Paul Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres Cordova";

    int svicmp( string_view lhs, string_view rhs );

    int main()
    {
    string_view svNames = ::Names;
    struct name { string_view forename, surname; };
    vector<name> names;
    auto parse = [&]<bool Regex>( bool_constant<Regex> )
    {
    if constexpr( Regex )
    {
    regex
    rxTotal( "\\s*([^,]+)(?:,|$)" ),
    rxRvSurname( "\\s*(\\S+)" ),
    rxRvGap( "\\s+" );
    match_results<string_view::iterator> totalMtch;
    match_results<string_view::reverse_iterator> rvMatch;
    for( auto itName = svNames.begin(); regex_search( itName,
    svNames.end(), totalMtch, rxTotal ); itName = totalMtch[0].second )
    {
    if( !regex_search( reverse_iterator( totalMtch[1].second ),
    reverse_iterator( totalMtch[1].first ), rvMatch, rxRvSurname ) )
    continue;
    auto
    itForename = totalMtch[1].first,
    itSurname = rvMatch[1].second.base(),
    itSurnameEnd = rvMatch[1].first.base();
    string_view surname( itSurname, itSurnameEnd ), forename;
    if( regex_search( reverse_iterator( itSurname ), reverse_iterator(
    itForename ), rvMatch, rxRvGap ) )
    forename = string_view( itForename, rvMatch[0].second.base() );
    else
    if( itSurname != itForename )
    continue;
    names.emplace_back( forename, surname );
    }
    }
    else
    {
    for( auto where = svNames.begin(); where != svNames.end(); )
    {
    static constexpr auto *whitespace = +[]( char c ) { return c == ' '
    || c == '\t' || c == '\r' || c == '\n'; };
    static constexpr auto *nonWs = +[]( char c ) { return !whitespace( c
    ); };
    auto
    itNameBegin = where,
    itNameEnd = find( itNameBegin, svNames.end(), ',' );
    if( itNameEnd == itNameBegin )
    break;
    where = itNameEnd + (itNameEnd != svNames.end());
    auto itSurnameEnd = find_if( reverse_iterator( itNameEnd ),
    reverse_iterator( itNameBegin ), nonWs ).base();
    if( itSurnameEnd == itNameBegin )
    continue;
    auto itSurname = find_if( reverse_iterator( itSurnameEnd ),
    reverse_iterator( itNameBegin ), whitespace ).base();
    string_view surname( itSurname, itSurnameEnd ), forename;
    auto
    itForenameEnd = find_if( reverse_iterator( itSurname ),
    reverse_iterator( itNameBegin ), nonWs ).base(),
    itForenameBegin = find_if( itNameBegin, itForenameEnd, nonWs );
    forename = string_view( itForenameBegin, itForenameEnd );
    names.emplace_back( forename, surname );
    }
    }
    };
    parse( false_type() );
    sort( names.begin(), names.end(), []( const name &lhs, const name &rhs )
    {
    int cmpSurname = svicmp( lhs.surname, rhs.surname );
    if( cmpSurname != 0 )
    return cmpSurname < 0;
    return svicmp( lhs.forename, rhs.forename ) < 0;
    } );
    for( const name &nm : names )
    cout << "\"" << nm.surname << "\", \"" << nm.forename << "\"" << endl;
    }

    int svicmp( string_view lhs, string_view rhs )
    {
    constexpr auto *lwtoi = +[]( char c ) -> int { return (unsigned char)tolower( c ); };
    size_t c = min( lhs.size(), rhs.size() );
    for( size_t i = 0; i < c; ++i )
    if( int d = lwtoi( lhs[i] ) - lwtoi( rhs[i] ); d )
    return d;
    return lhs.size() < rhs.size();
    }
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.c on Sun Apr 19 09:35:11 2026
    From Newsgroup: comp.lang.c

    On 2026-04-18 12:19, gggggggggggunit wrote:
    $ cat names.txt | tr -d '\n' | sed 's/,/\n/g' | sed 's/^ //g' | awk 'NF ==
    3 { print $1, $3, $2 } NF == 2 { print $1, $2 } NF ==1 { print $1 }' |
    sort -k 2,2 -k 1,1 | awk 'NF == 3 { print $1, $3, $2 } NF == 2 { print
    $1, $2 } NF ==1 { print $1 }'
    Uh-oh! - Why so complicated?

    (The cat is unnecessary, the tr as well, two seds can be combined,
    the awk's are unnecessarily bulky, ...)

    And this proposal also doesn't seem to sort the single letter data
    (to be interpreted as primary key like surnames) into the sequence.

    One terser way (including considering single word entities as the
    name to get sorted in like a surname) can be

    sed 's/, /\n/g' names.txt | awk '{print $NF"\t"$0}' |
    sort |
    sed 's/.*\t//'


    Janis

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.lang.c on Sun Apr 19 14:18:33 2026
    From Newsgroup: comp.lang.c

    In article <10s20jf$2b5i9$1@dont-email.me>,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    ...
    One terser way (including considering single word entities as the
    name to get sorted in like a surname) can be

    sed 's/, /\n/g' names.txt | awk '{print $NF"\t"$0}' |
    sort |
    sed 's/.*\t//'

    First, on the code of "code golfing" this: Surely, any construct of the
    form: sed ... | awk ...

    can be simplified into a single call to awk, since (with exceptions so few
    as to be irrelevant) anything sed can do, awk can do.

    And, of course, whatever the above command line is doing (I haven't
    followed this thread closely enough to know what it is actually about), can
    be done in a single invocation of GAWK (or TAWK), which has built-in
    sorting. It could also be done in a single invocation of any AWK (or Perl
    or whatever) if you are willing to write your own sort routine.

    And, of course, other posters should be along any minute with Perl (or Ruby
    or Python or ...) one-liners as well.

    Second, I would imagine that whoever constructed the original line (to
    which you responded) probably developed it from scratch by stringing things together and is quite proud of the effort, so he saw no need to trim it
    down for posting. Hence the appearance as it is.
    --
    "It does a lot of things half well and it's just a garbage heap of ideas that are
    mutually exclusive."

    - Ken Thompson, on C++ -
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.lang.c on Sun Apr 19 19:32:42 2026
    From Newsgroup: comp.lang.c

    In article <10s2o7p$25ao7$1@news.xmission.com>,
    Kenny McCormack <gazelle@shell.xmission.com> wrote:
    In article <10s20jf$2b5i9$1@dont-email.me>,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    ...
    One terser way (including considering single word entities as the
    name to get sorted in like a surname) can be

    sed 's/, /\n/g' names.txt | awk '{print $NF"\t"$0}' |
    sort |
    sed 's/.*\t//'

    First, on the code of "code golfing" this: Surely, any construct of the
    form: sed ... | awk ...

    can be simplified into a single call to awk, since (with exceptions so few
    as to be irrelevant) anything sed can do, awk can do.

    Probably. But I'm not sure that's all that useful in the
    general case. The `sed` command here is translating logical
    records into lines; the `awk` command is then prefixing those
    with the last token (and a tab). Then sorting, so that records
    are sorted by the last token, and then removing that token (and
    the tab).

    And, of course, whatever the above command line is doing (I haven't
    followed this thread closely enough to know what it is actually about), can >be done in a single invocation of GAWK (or TAWK), which has built-in
    sorting. It could also be done in a single invocation of any AWK (or Perl
    or whatever) if you are willing to write your own sort routine.

    One could, of course, do this in a single `awk` invocation. I
    suspect it would be rather more awkward.

    And, of course, other posters should be along any minute with Perl (or Ruby >or Python or ...) one-liners as well.

    Second, I would imagine that whoever constructed the original line (to
    which you responded) probably developed it from scratch by stringing things >together and is quite proud of the effort, so he saw no need to trim it
    down for posting. Hence the appearance as it is.

    *shrug* there's always a possibility to learn.

    I saw this and it made me wonder whether one could just use the
    `sort` command directly, and tell it to sort using the second
    field. However, some records don't _have_ a second key (they're
    single word) and some have 3 (some records have a middle initial
    for instance); these are things that the `sort` command just
    cannot handle, sadly.

    Then it made me think that it would be nice if there was a way
    to rotate the fields on a line; sadly, I'm not aware of a
    standard command that does that. But it's not too hard to write
    as its own little script.

    You then have something like,

    `sed 's/, */\n'g' data | rotwords -r | sort | rotwords -l`

    `rotwords -r` does a right-rotation (so the last field is moved
    to the front) and `rotwords -l` does a left rotation (so the
    first field is moved to the rear).

    It was kind of a fun exercise.

    - Dan C.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Rosario19@Ros@invalid.invalid to comp.lang.c on Mon Apr 20 21:20:28 2026
    From Newsgroup: comp.lang.c

    On Sat, 18 Apr 2026 11:16:48 +0200, Rosario19 wrote:

    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}{leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}{leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}

    Mordant
    taishi28012
    darrin
    ReallyBored
    TheFred
    Paul Abbott
    Neil Anuskiewicz
    Tim Bando
    Masa Bando
    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry
    Arnold F. Williams
    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    Liudmilla Karukina
    Ken Kennedy
    David L. Jessup
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang


    this is a C version

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>

    #define R return
    #define P printf

    char names[] = {"Martin Hohenberg, Jae Yang, Tim Bando, Daniel \
    Garber, Kyle Burkholder, Mike Nichols, Mark Ping, Tom Taylor, Arnold
    F. \
    Williams, George Brower, Michael Nygard, Brendan Long, Sven Dowideit,
    \
    Dave Witten, Jonathan Cast, James Cronin, David L. Jessup, Christopher
    \
    Chang, Killer Delicious, Jacob Lyles, Neil Anuskiewicz, Mordant,
    Clemens \
    Ladisch, Wojciech Woytniak, Masa Bando, John Carmack, Xingyu Wang,
    Jane \
    Tang, Steven Evans, Jan Roudaut, Hsueh Sung, Ken LaCrosse,
    taishi28012, \
    John Simpson, Jerod Tufte, Paul Abbott, Stan Witherspoon, Donald
    Greer, \
    Gratiela Chergu, Michael Ciagala, Dale Carstensen, Chip Davis,
    Liudmilla \
    Karukina, Jim McCloskey, Dewey Sasser, Hal Hildebrand, Connor Wood,
    Ken \
    Kennedy, darrin, Mark Gardner, William Christensen, Malcolm Ocean, Rod
    \
    Davenport, Nodarius Darjania, Cheryl Evry, Wenfeng Liang, Irving
    Rivas, \
    Bill Soistman, ReallyBored, Ron Lauzon, TheFred, Paul \
    Theodoropolous, Doug Phillips, Les Vogel, Matt Pollard, Andres
    Cordova"};

    int toNextWord(char* a)
    {int k,c,cnt;
    if(a[0]==0) R 0;
    if(a[1]==0||a[1]==',') R 0;
    k=0;
    if(a[k]==',')++k;
    for(cnt=0;c=a[k];++k)
    {if(c==0||c==',') R 0;
    if(isalnum(c))
    {if(cnt==1) R k;
    for(++cnt;isalnum(c=a[k]);++k);
    if(c==','||c==0)R 0;
    }
    }
    R 0;
    }

    char** rompiVettori(char* a)
    {int i, c, cnt, j, k;
    char **p, pc;

    for(i=0,cnt=0;c=a[i];++i)
    {if(c==',')++cnt;if(i>2e6||cnt>2e4) R 0;}
    cnt+=8;p=(char**)malloc(cnt*sizeof(char*));if(p==0) R 0;
    p[0]=a;
    for(i=0,j=1;c=a[i];++i)
    {if(c==',')p[j++]=a+i;
    if(i>2e6||j>2e4){free(p); R 0;}
    }
    k=j;
    for(j=0;j<k;++j)
    {i=toNextWord(p[j]);
    p[j]=p[j]+i;
    //P("%x %c%c ",p[j],p[j][0], p[j][1]);
    }
    p[j]=0;
    R p;
    }

    int wordcmp(const void* aa, const void* bb)
    {int ca,cb,i,j;
    char *a=*(char**)aa, *b=*(char**)bb;

    if(a==0)R -1;
    if(b==0)R 1;
    //P("%x %x\n", a, b);
    if(!isalnum(*a))R -1;
    if(!isalnum(*b))R 1;
    for(i=0;(ca=a[i])&&(cb=b[i]);++i)
    {if(!isalnum(ca)) R -1;
    if(!isalnum(cb)) R 1;
    ca=toupper(ca); cb=toupper(cb);
    if(ca<cb)R -1;
    if(ca>cb)R 1;
    }
    R -1;
    }

    int main()
    {int i,j,c;
    char **p=rompiVettori(names), *pc, *pf;

    if(p==0)R 0;

    for(j=0;names[j];++j);
    pf=names+j;

    /*
    P("fine=%x p=%x\n", pf,p);
    P("p[0]=%x names=%x\n", p[0], names);
    for(i=0;p[i];++i)
    P("%c%c ", p[i][0], p[i][1]);
    P("i=%d\n", i);
    */

    for(i=0;p[i];++i)
    ;
    qsort(p,i,sizeof(char*),wordcmp);

    for(i=0;p[i];++i)
    {for(pc=p[i];pc>names;--pc)
    if(*pc==',')break;
    if(*pc==',')++pc;
    for(j=0;pc+j<pf&&isspace(pc[j]);++j);
    for(;pc+j<pf&&(c=pc[j])&&','!=c;++j)
    {P("%c", c);}
    P("\n");
    }

    free(p);
    return 0;
    }

    ---------------------------------
    result:
    ---------------------------------
    TheFred
    taishi28012
    darrin
    ReallyBored
    Mordant
    Paul Abbott
    Neil Anuskiewicz
    Tim Bando
    Masa Bando
    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry
    Arnold F. Williams
    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    Liudmilla Karukina
    Ken Kennedy
    David L. Jessup
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From DFS@nospam@dfs.com to comp.lang.c on Mon Apr 20 16:43:28 2026
    From Newsgroup: comp.lang.c

    On 4/20/2026 3:20 PM, Rosario19 wrote:

    this is a C version

    <snip>

    ---------------------------------
    result:
    ---------------------------------
    TheFred
    taishi28012
    darrin
    ReallyBored
    Mordant
    Paul Abbott
    Neil Anuskiewicz


    ------------------
    Tim Bando
    Masa Bando
    ------------------
    fail


    George Brower
    Kyle Burkholder
    John Carmack
    Dale Carstensen
    Jonathan Cast
    Christopher Chang
    Gratiela Chergu
    William Christensen
    Michael Ciagala
    Andres Cordova
    James Cronin
    Nodarius Darjania
    Rod Davenport
    Chip Davis
    Killer Delicious
    Sven Dowideit
    Steven Evans
    Cheryl Evry

    ------------------------
    Arnold F. Williams
    ------------------------
    fail


    Daniel Garber
    Mark Gardner
    Donald Greer
    Hal Hildebrand
    Martin Hohenberg
    Liudmilla Karukina
    Ken Kennedy
    David L. Jessup
    Ken LaCrosse
    Clemens Ladisch
    Ron Lauzon
    Wenfeng Liang
    Brendan Long
    Jacob Lyles
    Jim McCloskey
    Mike Nichols
    Michael Nygard
    Malcolm Ocean
    Doug Phillips
    Mark Ping
    Matt Pollard
    Irving Rivas
    Jan Roudaut
    Dewey Sasser
    John Simpson
    Bill Soistman
    Hsueh Sung
    Jane Tang
    Tom Taylor
    Paul Theodoropolous
    Jerod Tufte
    Les Vogel
    Xingyu Wang
    Stan Witherspoon
    Dave Witten
    Connor Wood
    Wojciech Woytniak
    Jae Yang


    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c on Mon Apr 20 14:16:30 2026
    From Newsgroup: comp.lang.c

    Rosario19 <Ros@invalid.invalid> writes:
    [...]

    this is a C version

    [...]

    #define R return
    #define P printf

    Nope.

    [...]
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Rosario19@Ros@invalid.invalid to comp.lang.c on Tue Apr 21 05:00:56 2026
    From Newsgroup: comp.lang.c

    On Sat, 18 Apr 2026 11:16:48 +0200, Rosario19 wrote:

    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}{leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}{leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}


    {commabar}{leftbrace}k[{deltastile}{rightshoe}{uparrow}{dieresis}{leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}k{leftarrow}{leftbrace}({omega}{notequal}{apostrophe}
    {apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}]{rightbrace}s{cr}{lf}

    they are 40 chars if one not count input lenght and the assignament to
    a varible of it.

    The comment:

    ?{k[???¨{1??}¨k?{(??' ')??}¨(??',')??]}s
    s input -------------------------------------------------- ({omega}{notequal}{apostrophe},{apostrophe}){leftshoe}{omega}
    (??',')?? break the input s=? in the
    way each element is a string that contain elements between ,, -------------------------------------------------- {leftbrace}({omega}{notequal}{apostrophe}{apostrophe}){leftshoe}{omega}{rightbrace}{dieresis}
    {(??' ')??}¨ break each element of
    elements the above result array for separate name and surname --------------------------------------------------
    k{leftarrow}
    k?
    call that k, k is a list contain elements as ('firstName',
    'secondname')
    -------------------------------------------------- {leftbrace}1{downarrow}{omega}{rightbrace}{dieresis}
    {1??}¨ from each element of k, cut
    the first
    --------------------------------------------------
    {uparrow}{dieresis}
    ?¨ so remain the second...
    disclose it
    --------------------------------------------------
    {rightshoe}
    ? build one matrix of the second names this is
    only because ? return indices ordered lexicographic on lines --------------------------------------------------
    {deltastile}
    ? order indices --------------------------------------------------
    {k[?..........] show k of these index --------------------------------------------------
    {commabar}
    ? show one name surname for line

    for me in APL the process of programming is show in the screen each
    change of input using the next function (or imagine that)
    in C the same.

    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Rosario19@Ros@invalid.invalid to comp.lang.c on Tue Apr 21 05:06:54 2026
    From Newsgroup: comp.lang.c

    On Tue, 21 Apr 2026 05:00:56 +0200, Rosario19 wrote:

    for me in APL the process of programming is show in the screen each
    change of input using the next function (or imagine that)
    in C the same.

    In C there is to think more than APL for edge cases that can happen
    --- Synchronet 3.21f-Linux NewsLink 1.2