“Inversion de chaîne en c” Réponses codées

Inversion de chaîne en c

// Reverse a string using pointers:

#include <stdio.h>

void rev(char *str)
{
	char *r_ptr = str;
	while (*(r_ptr + 1) != '\0')
		r_ptr++;

	while (r_ptr > str)
	{
		char tmp = *r_ptr;
		*r_ptr-- = *str;
		*str++ = tmp;
	}
}

void main()
{
	char s[] = "Hello World!";
	rev(s);
	puts(s); // Prints !dlroW olleH
}
IgnitedIce

comment inverser une chaîne en c


#include <stdio.h>
#include <string.h>

int main()
{
    char str[2][100];
    printf("Type Text: ");

    scanf("%[^\n]%*c", str[0]);
    int length = strlen(str[0]);
    int i, j;
    for (i = 0, j = length - 1; i < length; i++, j--)
    {
        str[1][i] = str[0][j];
    }
    printf("Original Word: %s\n", str[0]);
    printf("Reverse word: %s\n", str[1]);
    return 0;
}
Numan from Bangladesh

Inversion de chaîne en c

ath = ATH
smartBOY = yobTRAMS
Clear Cow

Inversion de chaîne en c

2
ath
smartBOY

Case #1: HTA
Case #2: yobTRAMS
Clear Cow

Inversion de chaîne en c

#include<stdio.h>

void revAString(char strg[])
{
    int g, numb;
    int tmpry = 0;

    for(numb=0; strg[numb] != 0; numb++);
    for(g = 0; g <numb/2; g++)
    {
        tmpry = strg[g];
        strg[g]=strg[numb - 1 - g];
        strg[numb - 1 - g] = tmpry;
    }
    for(g = 0; g < numb; g++)
        putchar(strg[g]);
    printf(" \n ");
}

int main(void)
{
    char strg[60]; 
    printf("Please insert the string you wish to get reversed: ");
    scanf("%s", strg); 
    revAString(strg);
    return 0;
}
Tiny Coders

Inversion de chaîne en c

smartBOY
Clear Cow

Réponses similaires à “Inversion de chaîne en c”

Questions similaires à “Inversion de chaîne en c”

Plus de réponses similaires à “Inversion de chaîne en c” dans C

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code