bug

does i have done some mistake in my code below?
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
#include <iostream>
#include <conio.h>
using namespace std;

void char_encrypt (char * modif_char) {
	int count = 0;
	while (*(modif_char + count) != '\n') {
		//shift + 2
		*(modif_char + count) = *(modif_char + count) + 2;
		++count;
	}
}

int main () {
	char some_chars [] 	= "a simple test...";
	char_encrypt (some_chars);

	for (int count = 0; count < sizeof (some_chars); ++count) {
		cout << some_chars[count] << endl;
	}

	cout << "press any key to continue...";
	getch();
	return 0;
}


the result is: blank console
the error message is:


Unhandled exception at 0x02431298 in C_test.exe: 0xC0000005: Access violation reading location 0x02431298.


please help...
The call to getch() might be your problem.


Last edited on
Maybe test for null rather then newline.while (*(modif_char + count) != '\0') {
The string terminator is '\0'
x_x my bad... (embarrassing)
Topic archived. No new replies allowed.