Function Input

char s[], char c 
  • What do you mean by repetitions? Find where two identical letters appear in a row? - Harry
  • @Harry No, they give me a set of characters char s [], and the character char c. I need to find at what positions of the vector S is the character "char C". - MrShef
  • strchr() to help you, for example ... - Harry

1 answer 1

Something in this spirit:

 char s[] = "vsjkhgvsdfvk sdfgjhsbdfjhgsd jhfjklhfsdklhkhskdf"; char c = 'j'; char * p = s; while(p = strchr(p,c)) printf("at pos %d\n",p++-s); 
  • Is it possible on C, but not with ++? I don't understand the last 2 lines - MrShef
  • @MrShef do not believe it is clean with. On c ++ it would be different. - pavel
  • @MrShef Did, sorry. Meaning - look for, find - display and proceed to search from the next character . There may be a compiler warning about assignment in while , but this is how it should be. Well, or replace with while((p = strchr(p,c)) != NULL) . - Harry
  • @Harry yes the question was not about a typo, the question is that people are not used to working with pointers like this. - pavel
  • one
    p is the current position of the last character found in the string. Just know, let us work on your own, experiment, read, so you’ll have much better used methods in your memory ... - Harry