[ create a new paste ] login | about

Link: http://codepad.org/T1e5NvpC    [ raw code | output | fork ]

C, pasted on Sep 13:
#include <stdio.h>
#include <stdlib.h>

void swapValues(char a[], int size);
void printArray(char arr[], int size);

int main() {
        char my_str[6]; // C-style string will hold the string 
        my_str[0] = 's';
        my_str[1] = 't';
        my_str[2] = 'r';
        my_str[3] = 'i';
        my_str[4] = 'n';
        my_str[5] = 'g';
        my_str[6] = '\0';


        printArray(my_str,6);
        swapValues(my_str,6);
        printArray(my_str,6);

        return 0;

}

void swapValues(char a[], int size){
        char temp;
        int i;
        for (i = 0; i < ((sizeof(a) / sizeof(char) / 2) -1); i ++){
                temp = a[i];
                a[i] = a[((sizeof(a) / sizeof(char))) -i];
                a[((sizeof(a) / sizeof(char))) -i] = temp;
        }
}

void printArray(char arr[], int size) {
        printf("%d elements:\n", size);

        int i;
        for(i=0; i < size; i++) {
                printf("%c ", arr[i]);
        }
        printf("\n");

}


Output:
1
2
3
4
6 elements:
s t r i n g 
6 elements:
n t r i s g 


Create a new paste based on this one


Comments: