What the hell is happening here? Why is h changing to p?

What the hell is happening here?
Why is h changing to p?

Mike Stoklasa's Worst Fan Shirt $21.68

Shopping Cart Returner Shirt $21.68

Mike Stoklasa's Worst Fan Shirt $21.68

  1. 2 years ago
    Anonymous

    Nigeria

    • 2 years ago
      Anonymous

      Explain.

  2. 2 years ago
    Anonymous

    why don't you step through the dubugger you moron and see why

    • 2 years ago
      Anonymous

      Frick you b***h, I don't know how to use the debugger, explain it.

      • 2 years ago
        Anonymous

        No. Learn to use the debugger.

        • 2 years ago
          Anonymous

          maybe its time to learn and stop being a useless Black person.

          You are actually the useless one.
          If someone asks a question, you don't tell them to go somewhere else your mentally braindead moron. Learning is exactly what I am doing right now you homosexual, this is impossible to learn without outside guidance, this is a moron system built by morons like you, so either explain it or shut the frick up you worthless sack of shit.

          • 2 years ago
            Anonymous

            >learning is what I am doing right now
            >NO I REFUSE TO USE THE TOOL DESIGNED EXACTLY TO TELL ME HOW TO SEE WHAT IS HAPPENING

            google "how to use <MY IDE> <MY LANGUAGE> <DEBUGGER>"

      • 2 years ago
        Anonymous

        maybe its time to learn and stop being a useless Black person.

    • 2 years ago
      Anonymous

      No. Learn to use the debugger.

      maybe its time to learn and stop being a useless Black person.

      [...]
      You are actually the useless one.
      If someone asks a question, you don't tell them to go somewhere else your mentally braindead moron. Learning is exactly what I am doing right now you homosexual, this is impossible to learn without outside guidance, this is a moron system built by morons like you, so either explain it or shut the frick up you worthless sack of shit.

      >learning is what I am doing right now
      >NO I REFUSE TO USE THE TOOL DESIGNED EXACTLY TO TELL ME HOW TO SEE WHAT IS HAPPENING

      google "how to use <MY IDE> <MY LANGUAGE> <DEBUGGER>"

      Somebody should ban this homosexual everytime he posts, you are such a b***h.

  3. 2 years ago
    Anonymous

    char s2[i3];

    kys

    • 2 years ago
      Anonymous

      Nothing wrong with that you fricking idiot, you don't know shit so shut the frick up.

  4. 2 years ago
    Anonymous

    post the code as text if you want help

  5. 2 years ago
    Anonymous

    #include <stdio.h>
    main()
    {
    char string[] = {' ','h','e','l','l','o',' ',' ',''};
    printf("%sn",trim(string));
    }

    * trim(char s1[])
    {
    int i1 = 0; //char array index
    int i2 = 0; //start index
    int i3 = 0; //word indicator
    int i4 = 0; //end cut measure
    while(s1[i1] != '')
    {
    if(s1[i1] == ' ' || s1[i1] == 't' || s1[i1] == 'n')
    {
    i3 = 0;
    i4++;
    }
    else
    {
    if(i2 == 0)
    {
    i2 = i1;
    }
    i3 = 1;
    i4 = 0;
    }
    i1++;
    }
    i1 = i1 - i4; //end
    i3 = i2 - i1 + 1; //length
    i4 = 0; //newIndex
    char s2[i3];
    while(i2 < i1)
    {
    s2[i4] = s1[i2];
    printf("s2:%c, s1:%cn",s2[i4],s1[i2]);
    i2++;
    i4++;
    }
    return s2;
    }

    • 2 years ago
      Anonymous

      Among other things, you calculate i3 as -4 and you return an array allocated on stack (s2) which is a clear mistake. It doesn't output s2:p for me, it outputs s2:h even with your broken code. I got it to work fully after fixing the two errors I mentioned above.

      • 2 years ago
        Anonymous

        Omg thank you.

        • 2 years ago
          Anonymous

          After line 35, values of indices are:
          i1 = 6
          i2 = 1
          i3 = -4
          i4 = 0
          Your logic is wrong. i3 shouldn't be negative.

          In the while loop on line 37:
          When you copy i1 to i2, you forget to copy the '' character.

          On line 9:
          What the frick is return type *? It should be char *

          And so on...

          Take it slow. Do it step by step. You've gone wayyyyy ahead of yourself with this program.

          Learn to step through your code by hand. Using a debugger comes after that.

          Now frick off and study.

          >Omg
          *vomit*

          • 2 years ago
            Anonymous

            correction:
            when you copy s1 to s2

            main.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
            2 | main()
            | ^~~~
            main.c: In function ‘main’:
            main.c:5:19: warning: implicit declaration of function ‘trim’ [-Wimplicit-function-declaration]
            5 | printf("%sn",trim(string));
            | ^~~~
            main.c:5:14: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
            5 | printf("%sn",trim(string));
            | ~^ ~~~~~~~~~~~~
            | | |
            | | int
            | char *
            | %d
            main.c: At top level:
            main.c:9:3: warning: return type defaults to ‘int’ [-Wimplicit-int]
            9 | * trim(char s1[])
            | ^~~~
            main.c:9:3: error: conflicting types for ‘trim’
            main.c:5:19: note: previous implicit declaration of ‘trim’ was here
            5 | printf("%sn",trim(string));
            | ^~~~
            main.c: In function ‘trim’:
            main.c:44:12: warning: returning ‘char *’ from a function with incompatible return type ‘int *’ [-Wincompatible-pointer-types]
            44 | return s2;
            | ^~
            main.c:44:12: warning: function returns address of local variable [-Wreturn-local-addr]

            Yes exactly. Don't know which compiler OP is using. trim function returns a pointer to s2. And s2 doesn't have a '' terminating character.
            OP is a confirmed moron and possibly also a troony.

          • 2 years ago
            Anonymous

            contd...
            OP is an actual moron.
            Now that I look at this program again...
            What the frick is that on line 36?
            char s2[i3];???????!!!!!!!
            Either dynamically declare a new array based on the length or declare the size a large constant.
            And don't forget to terminate your string with a ''.
            What an absolute fricking moron.

          • 2 years ago
            Anonymous

            You can do variable size length arrays in C and this is C. The mistake is returning s2, which should not be done regardless if the length is variable or constant.

          • 2 years ago
            Anonymous

            contd...
            OP is an actual moron.
            Now that I look at this program again...
            What the frick is that on line 36?
            char s2[i3];???????!!!!!!!
            Either dynamically declare a new array based on the length or declare the size a large constant.
            And don't forget to terminate your string with a ''.
            What an absolute fricking moron.

            People like you should be gunned down. You probably learnt everything from somebody else or copy pasted everything you wienersucking boomer b***h homosexual have a nice day.

          • 2 years ago
            Anonymous

            contd...
            OP is an actual moron.
            Now that I look at this program again...
            What the frick is that on line 36?
            char s2[i3];???????!!!!!!!
            Either dynamically declare a new array based on the length or declare the size a large constant.
            And don't forget to terminate your string with a ''.
            What an absolute fricking moron.

            Lose some weight you fat frick.

      • 2 years ago
        Anonymous

        #include <stdio.h>
        main()
        {
        char string[] = {' ','h','e','l','l','o',' ',' ',''};
        printf("%sn",trim(string));
        }

        * trim(char s1[])
        {
        int i1 = 0; //char array index
        int i2 = 0; //start index
        int i3 = 0; //word indicator
        int i4 = 0; //end cut measure
        while(s1[i1] != '')
        {
        if(s1[i1] == ' ' || s1[i1] == 't' || s1[i1] == 'n')
        {
        i3 = 0;
        i4++;
        }
        else
        {
        if(i2 == 0)
        {
        i2 = i1;
        }
        i3 = 1;
        i4 = 0;
        }
        i1++;
        }
        i1 = i1 - i4; //end
        i3 = i2 - i1 + 1; //length
        i4 = 0; //newIndex
        char s2[i3];
        while(i2 < i1)
        {
        s2[i4] = s1[i2];
        printf("s2:%c, s1:%cn",s2[i4],s1[i2]);
        i2++;
        i4++;
        }
        return s2;
        }

        As to why it might be printing p, one possibility is with your i3 calculated as -1, s2[i4] = s1[i2]; line could actually be modifying s2, not the data inside that array, but the actual pointer in memory. So after that assignment that points to some random place in memory, and contents at that address happen to be p. After that there is no modifying of the pointer, so all assignments work as they should.

        • 2 years ago
          Anonymous

          Yep needs to be
          #include <stdio.h>
          main()
          {
          char string[] = {' ','h','e','l','l','o',' ',' ',''};
          printf("%sn",trim(string));
          }

          * trim(char s1[])
          {
          int i1 = 0; //char array index
          int i2 = 0; //start index
          int i3 = 0; //word indicator
          int i4 = 0; //end cut measure
          while(s1[i1] != '')
          {
          if(s1[i1] == ' ' || s1[i1] == 't' || s1[i1] == 'n')
          {
          i3 = 0;
          i4++;
          }
          else
          {
          if(i2 == 0)
          {
          i2 = i1;
          }
          i3 = 1;
          i4 = 0;
          }
          i1++;
          }
          i1 = i1 - i4; //end
          i3 = i1 - i2 + 1; //length
          i4 = 0; //newIndex
          char s2[i3];
          while(i2 < i1)
          {
          s2[i4] = s1[i2];
          printf("s2:%c, s1:%cn",s2[i4],s1[i2]);
          i2++;
          i4++;
          }
          return s2;
          }

  6. 2 years ago
    Anonymous

    cool memory management, ahmed

  7. 2 years ago
    Anonymous

    >not wasting time on this crap
    learn to debug homosexual

  8. 2 years ago
    Anonymous

    Cleanup your code and maybe someone will be able to read it.

  9. 2 years ago
    Anonymous

    People like OP is the reason why Rust exists.

    • 2 years ago
      Anonymous

      I'm pretty sure OP isn't a troony.

      • 2 years ago
        Anonymous

        >I'm pretty sure OP isn't a troony.
        Nice try, OP.

  10. 2 years ago
    Anonymous

    main.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
    2 | main()
    | ^~~~
    main.c: In function ‘main’:
    main.c:5:19: warning: implicit declaration of function ‘trim’ [-Wimplicit-function-declaration]
    5 | printf("%sn",trim(string));
    | ^~~~
    main.c:5:14: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
    5 | printf("%sn",trim(string));
    | ~^ ~~~~~~~~~~~~
    | | |
    | | int
    | char *
    | %d
    main.c: At top level:
    main.c:9:3: warning: return type defaults to ‘int’ [-Wimplicit-int]
    9 | * trim(char s1[])
    | ^~~~
    main.c:9:3: error: conflicting types for ‘trim’
    main.c:5:19: note: previous implicit declaration of ‘trim’ was here
    5 | printf("%sn",trim(string));
    | ^~~~
    main.c: In function ‘trim’:
    main.c:44:12: warning: returning ‘char *’ from a function with incompatible return type ‘int *’ [-Wincompatible-pointer-types]
    44 | return s2;
    | ^~
    main.c:44:12: warning: function returns address of local variable [-Wreturn-local-addr]

Your email address will not be published. Required fields are marked *