Search
 
SCRIPT & CODE EXAMPLE
 

C

reverse of a string in c

#include<stdio.h>
#include<string.h>
void reverse(char str[100],int n);
void main(){
    char str[100];
    int n;
    printf("Enter a string : ");
    gets(str);
    reverse(str,n);
    printf("%s",str);

}
void reverse(char str[100],int n){
    n = strlen(str);
    for(int i=0;i<n/2;i++){
    char straight = str[i];
    char reverse = str[n-i-1];
    str[i] = reverse;
    str[n-i-1] = straight;
}
}
Comment

reverse string in c

// Reverse a string using pointers:

#include <stdio.h>

void rev(char *str)
{
	char *r_ptr = str;
	while (*(r_ptr + 1) != '')
		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
}
Comment

how to reverse a string in c


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

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

    scanf("%[^
]%*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
", str[0]);
    printf("Reverse word: %s
", str[1]);
    return 0;
}
Comment

reverse string in 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(" 
 ");
}

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

c Write a program to reverse an array or string

// Iterative C program to reverse an array
#include<stdio.h>
 
/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
    int temp;
    while (start < end)
    {
        temp = arr[start];  
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }  
}    
 
/* Utility that prints out an array on a line */
void printArray(int arr[], int size)
{
  int i;
  for (i=0; i < size; i++)
    printf("%d ", arr[i]);
 
  printf("
");
}
 
/* Driver function to test above functions */
int main()
{
    int arr[] = {1, 2, 3, 4, 5, 6};
    int n = sizeof(arr) / sizeof(arr[0]);
    printArray(arr, n);
    rvereseArray(arr, 0, n-1);
    printf("Reversed array is 
");
    printArray(arr, n);   
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: time now C 
C :: Happy New Year! 
C :: fibonacchi series in c 
C :: recursion c prime number 
C :: C Macros using #define 
C :: babel customelement plugins 
C :: docker logs follow 
Dart :: flutter debug tag 
Dart :: navigator.pushandremoveuntil flutter 
Dart :: change color of drawer icon flutter 
Dart :: flutter check if string is number 
Dart :: make a rounded container flutte 
Dart :: dart round to 2 decimals 
Dart :: flutter network image size 
Dart :: options = null firebaseoptions cannot be null when creating the default app. flutter 
Dart :: circular elevated button flutter 
Dart :: scaffold background color gradient 
Dart :: flutter button with icon 
Dart :: send null icon flutter 
Dart :: Attribute application@icon value=(@mipmap/launcher_icon) from AndroidManifest.xml:17:9-45 
Dart :: how to disable switch in flutter 
Dart :: customize dialog flutter 
Dart :: remove object key dart 
Dart :: dart remainder 
Dart :: call phone number flutter 
Dart :: flutter snackbar position 
Dart :: dart switch case 
Dart :: Flutter(Dart) Find String Length 
Dart :: flutter remove dropdown shadow appbar 
Dart :: toast message in flutter 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =