C/C++: Pointer sur une chaîne de caractère et inverser la chaîne

Author:


Download


#include 
#include 

void inverserString( char* str)
{
  char ch;
  for ( int i = 0, j = strlen(str)-1;  i < j;  ++i, --j )
    ch = str[i],  str[i] = str[j],  str[j] = ch;
}

int main(void)
{
  char str1[] = "Bienvenur sur www.mesexemples.com";

  printf("Chaîne originale:%sn",str1);

  inverserString(str1);

  printf("Chaîne inversée:%sn",str1);

  return 0;
}

Leave a Reply

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