• Counting Characters!!

    From DMZ@21:1/5 to All on Sat Sep 14 04:59:09 2024
    XPost: alt.comp.lang.c++.misc

    This simple program will count characters for you!!

    #include <stdio.h>

    int main()
    {
    printf(" = %d characters", printf("Hello World!"));

    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Ahlstrom@21:1/5 to DMZ on Sat Sep 14 15:41:37 2024
    XPost: alt.comp.lang.c++.misc

    DMZ wrote this copyrighted missive and expects royalties:

    This simple program will count characters for you!!

    #include <stdio.h>

    int main()
    {
    printf(" = %d characters", printf("Hello World!"));

    return 0;
    }

    Cute.

    --
    You can tell how far we have to go, when FORTRAN is the language of supercomputers.
    -- Steven Feiner

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Terry@21:1/5 to Chris Ahlstrom on Sat Sep 14 22:04:00 2024
    XPost: alt.comp.lang.c++.misc

    On 14/09/2024 20:41, Chris Ahlstrom wrote:
    DMZ wrote this copyrighted missive and expects royalties:

    This simple program will count characters for you!!

    #include <stdio.h>

    int main()
    {
    printf(" = %d characters", printf("Hello World!"));

    return 0;
    }

    Cute.


    Right - if you want a program that tells you there are 12 characters in the string "Hello world!"
    this one is right up there with the others... But the technique used doesn't always work - TAKE
    CARE when adapting the code for your own programs!

    Mike.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to All on Mon Sep 16 16:08:14 2024
    XPost: alt.comp.lang.c++.misc

    On Mon, 16 Sep 2024 17:55:02 +0200
    Bonita Montero <Bonita.Montero@gmail.com> boringly babbled:
    Am 14.09.2024 um 21:41 schrieb Chris Ahlstrom:
    DMZ wrote this copyrighted missive and expects royalties:

    This simple program will count characters for you!!

    #include <stdio.h>

    int main()
    {
    printf(" = %d characters", printf("Hello World!"));

    return 0;
    }

    Cute.


    Nice, but this counts the characters at compile-time:

    std::string_view sv( "Hello World!" );
    std::cout << sv << " = " << sv.length() << " characters" << endl;

    So does sizeof("Hello world!");

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to All on Tue Sep 17 07:21:37 2024
    XPost: alt.comp.lang.c++.misc

    On Mon, 16 Sep 2024 19:08:14 +0200
    Bonita Montero <Bonita.Montero@gmail.com> boringly babbled:
    Am 16.09.2024 um 18:08 schrieb Muttley@dastardlyhq.com:
    On Mon, 16 Sep 2024 17:55:02 +0200
    Bonita Montero <Bonita.Montero@gmail.com> boringly babbled:
    Am 14.09.2024 um 21:41 schrieb Chris Ahlstrom:
    DMZ wrote this copyrighted missive and expects royalties:

    This simple program will count characters for you!!

    #include <stdio.h>

    int main()
    {
    printf(" = %d characters", printf("Hello World!"));

    return 0;
    }

    Cute.


    Nice, but this counts the characters at compile-time:

    std::string_view sv( "Hello World!" );
    std::cout << sv << " = " << sv.length() << " characters" << endl;

    So does sizeof("Hello world!");


    But sizeof(string_literal) includes the null-terminating character.

    Gosh! Maybe you could do sizeof()-1 then. Just a thought!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)