Home / utk / cs102 / fa16 / labi / code_snippets / section1 / array_reference.cpp
Directory Listing
array_reference.cpp
getline.cpp
isstream.cpp
namelist.txt
numbers.txt
osstream.cpp
recordgen.c
result2.txt
result4.txt
student_info.cpp
sum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

const int STR_SIZE = 4;

void reverse_string(string [], int);

int main() {
	string str[] = {
		"Clara Nguyen",
		"Mom",
		"Dammit Im Mad",
		"aibohphobia"
	};
	reverse_string(str, STR_SIZE);
	
	for (int i = 0; i < STR_SIZE; i++) {
		cout << str[i] << endl;
	}
}

void reverse_string(string str[], int size) {
	int index_r;
	char temp;
	
	for (int i = 0; i < size; i++) {
		for (int j = 0; j < str[i].length() / 2; j++) {
			index_r = str[i].length() - j - 1;
			temp = str[i][j];
	
			str[i][j      ] = str[i][index_r];
			str[i][index_r] = temp;
		}
	}
}