-8

Yesterday, my answer got deleted by a moderator (@sideshowbarker). Being new to Stack Overflow, it's possible I broke a rule without knowing it, but could I get the reason so that I don’t repeat my mistakes? Thanks.

It was an answer for this question and here is my answer.

I am pretty sure my answer wasn’t a duplicate since I answered shortly after the question was asked and did not copy anyone for it. Also my answer provided corrected code and a link to a similar question as well as an explanation of the answer, so I didn’t find the rule I broke.

Since I am not sure my answer is visible, I am going to post what I wrote here.

The expressions (*count)++ and *count++ may seem similar, but they have different meanings and can produce different results.

(*count)++ is equivalent to (*count) += 1, which means "increment the value pointed to by count by 1, and return the original value". This expression modifies the value stored at the memory location pointed to by count, and then returns the original value before the increment.

*count++ is equivalent to *(count++), which means "return the value pointed to by count, and then increment count to point to the next memory location". This expression does not modify the value stored at the memory location pointed to by count, but rather advances the pointer to the next location in the memory.

In the case of the code posted in the question, using *count++ in the loop would not update the value of the variable count in the calling function, because it only changes the pointer locally within the loop. On the other hand, using (*count)++ correctly updates the value of the variable count by incrementing it by 1 for each occurrence of the key character in the input string.

Here is a correction of your code that works as intended

#include <stdio.h>
#include <string.h>
void q(char S[], char key, int *count){
   int i, n;
   *count=0;
   n=strlen(S);
   for(i=0;i<n;i++){
       if(S[i]==key){
           (*count)++;
           printf("found at index %d\n", i);
       }
   }
}


void main(){
   char S[]={'a','b','c','b','c','e','d','c','f'};
   char key='c';
   int *counter,count;
   counter=&count;
   q(S,'c', counter);
   printf("C found %d times\n", *counter);
}
```>


PS: The question was already answered [here](https://stackoverflow.com/questions/20931206/incrementing-pointers-value-doesnt-work/)!
18
  • 8
    Chances of having used generative models aside, what is with the PS at the end? Are you suggesting that the question that you were answering was already answered by another question? If this is the case, the best course of action is to flag the question as a duplicate of the other one, instead of posting another answer. May 15 at 9:09
  • 1
    Well I answer the question and then realized later that another question on stackoverflow had the same problem, so i linked the question thinking either a mod would close the question if he thought it was a duplicate or that the OP would get better answer there. I am still new to SO so i dont feel qualified to flag a question.
    – Osamodas
    May 15 at 9:13
  • Hmm, I had to look again. The flagging privilege would come at 15 reputation. You are very close! May 15 at 9:19
  • 11
    Your Answer feels very 'ChatGPT' to me, to be honest... The English/grammar/punctuation are perfect in it, while the bits written by you "personally" use a "very approx" English...
    – chivracq
    May 15 at 9:20
  • 3
    Yeah english is not my first language, so i wrote my answer and let chatgpt fix the grammar and synthax. I know generating answer is against the rule but i wrote my answer first and verified that the explanation was still the same . However if this is against the rule too i will stop.
    – Osamodas
    May 15 at 9:24
  • 6
    Indeed, zerogpt.com identifies basically all of the prose as AI-generated.
    – tripleee
    May 15 at 9:24
  • I see, thanks for the answer. I guess i will have to improve my writing level then.
    – Osamodas
    May 15 at 9:26
  • 10
    @Osamodas the problem with AI refined answers would be that it would be difficult for the moderators to validate that (Otherwise everyone would say that). I believe there are various tools out there that help you to correct your grammar maybe you should use those? Even if you post with grammar that is bad, as long as your post is understandable you'd find that there are people willing to edit and fix the grammar for you (As long as your post gets these users attention) May 15 at 9:45
  • 1
    Indeed, there are certainly tools out there that can help improve the grammar that aren't OpenAI tools. Even native English speakers use them.
    – Thom A
    May 15 at 10:09
  • 2
    Thanks for your answers. I will abstain from using OpenAI to correct my posts in the futur. Thank you for taking the time to point out what i did wrong in my post. I will check the non AI powered grammar corrector out there.
    – Osamodas
    May 15 at 10:24
  • 3
    ESL is not an excuse for not capitalising "i". It doesn't require any skills, so there is probably another reason. May 15 at 10:37
  • 2
    I wasn't aware that capitalising "i" was a rule in english, my bad.
    – Osamodas
    May 15 at 10:42
  • 1
    It's probably possible to ask ChatGPT to not change the wording and only correct mistakes, but I used it because I dont like how the english sentences I write turn out (on top of correcting mistakes).
    – Osamodas
    May 15 at 10:49
  • 2
    @Osamodas - Besides the fact ChatGPT was involved, you answered a duplicate question, instead of flagging it as a duplicate. Don’t use ChatGPT to correct your grammar, there are other tools that exist, that won’t generate content that is so obviously generated by an AI May 15 at 11:53
  • 4
    @Osamodas I would suggest enabling spelling checkers in your browser. That alone will probably fix most of the issues you now used ChatGPT for... It also takes no effort, and works when writing comments...
    – Cerbrus
    May 15 at 12:24

1 Answer 1

8

Posting the same answer to multiple questions should generally be avoided. If they are really so similar as to deserve the same answer, the new question should be closed as a duplicate of the earlier one.

At your privilege level, you cannot participate in this curation effort, but you can at least abstain from posting duplicate answers. Once you reach 15 reputation points, you should be able to flag as duplicate.

2
  • Thanks for your answer. I didnt realise it was a duplicate at first, i only found out later and added in a PS. I will try to stay away from duplicate question for now
    – Osamodas
    May 15 at 9:16
  • 5
    "Once you earn enough reputation to add comments on questions, you are most welcome to add a comment to suggest closing as a duplicate." Or even better, flag as a duplicate (which automatically posts a comment, but also adds the question to the review queue). They will also be able to flag before they can comment, since 50 reputation is required to comment but only 15 reputation is required to flag. May 15 at 10:56

Not the answer you're looking for? Browse other questions tagged .