Error Reading Characters of String Unable to Read Memory

shiftyape
Feb 23, 2013
48
0
x,580
0
  • #i
fist of al, dont critisize me for being unoriginal, stupid, or lame. the error im getting is:
<fault reading characters of string>
<unable to read retentiveness>

#include <iostream>
#include <cmath>
#include <Windows.h>
#include <ctime>
#include <cstdlib>
#include <conio.h>
#include <cstring>
using namespace std;

int principal() {

char* space[39] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ",
" ", " ", " ", " ",
" ", " ", " ", " ",
" ", " "};

int a, b, c, d;

char central = ' ';
cout << "utilize wasd to move around" << endl;

Sleep(3000);

cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl;

a = 38;
b = 39;
c = 35;
d = 34;

while (1) {
system("cls");
cout << space[a] << "/\\" << endl; //38
cout << space << "/ \\" << endl; //39
cout << space << "| |" << endl; //39
cout << space << "| |" << endl; //39
cout << space[a] << "/ \\" << endl; //38
cout << space[c] << "--- ---" << endl; //35
cout << space[d] << "/ \\" << endl; //34
cout << space[d] << "----- ----" << endl; //34
cout << space << "| |" << endl; //39
cout << space << "/ \\" << endl; //39
cout << space << "-------" << endl; //39

char left = 'a';
char right = 'd';
char downward = 's';
char up = 'west';

key = _getch();

if (key == left)
{
a = a - ane;
b = b - 1;
c = c - 1;
d = d - one;
}
else if (key == right)
{
a = a + i;
b = b + i;
c = c + 1;
d = d + ane;
}
}

organisation("PAUSE");
render 0;
}

// i know i suck at writing lawmaking simply try and help anyway

Jun 4, 2012
226
0
10,860
seven
  • #3
First you shouldn't be asking for homework help here.
Second the compiler it would help if you explained what information technology'south suppose to do. I've institute in well-nigh cases that errors result when people don't understand what it is that they demand the lawmaking to do.

Your lawmaking has a number of different issues, your naming isn't consistent, your indentation isn't consistent, and your structure is a disaster. You shouldn't use system to clear the screen or pause, there are portable solutions to this. You demand to clean upwardly the code beginning and the error should become clear. To exist fair I see several problems that would be resolved through cleaner data structures and simpler code.

getochkn
Jul 2, 2006
1,621
0
21,960
368
  • #two
if this is for a homework assignment or something, well, learn how to practise it and don't ask others to practice your homework.
Jun 4, 2012
226
0
ten,860
7
  • #iii
First you shouldn't be asking for homework assist here.
Second the compiler information technology would help if yous explained what it'south suppose to exercise. I've found in almost cases that errors event when people don't empathize what information technology is that they need the code to do.

Your lawmaking has a number of different issues, your naming isn't consistent, your indentation isn't consistent, and your structure is a disaster. You shouldn't use system to articulate the screen or pause, there are portable solutions to this. You demand to clean up the code first and the error should become clear. To be fair I see several issues that would be resolved through cleaner information structures and simpler code.

ksham
Mar 29, 2013
175
0
10,760
25
  • #4
I may exist incorrect, but the likely cause is accessing index 39. It'south goose egg-index so they start at 0 and end at 38, not 1 - 39.
Jun 4, 2012
226
0
10,860
7
  • #5
I may exist wrong, but the likely cause is accessing index 39. It's zero-index then they start at 0 and end at 38, non 1 - 39.

This is why I advised restructuring the code, there's a much bigger problem with the "array". In fact I would be surprised if the code compiles without several pages worth of warnings.

ex_bubblehead
Aug 24, 2012
671
ane
xx,115
134
shiftyape
Feb 23, 2013
48
0
10,580
0
  • #7
First you lot shouldn't exist asking for homework help here.
Second the compiler information technology would help if you lot explained what it'south suppose to do. I've found in virtually cases that errors result when people don't understand what it is that they demand the code to do.

Your code has a number of different bug, your naming isn't consistent, your indentation isn't consequent, and your construction is a disaster. Y'all shouldn't apply system to clear the screen or pause, there are portable solutions to this. You need to clean up the lawmaking first and the error should get clear. To exist off-white I meet several problems that would be resolved through cleaner information structures and simpler code.

this isnt a homework assignment, its just something i made in my spare time for fun. thanks for answering though. i volition try and fix that stuff. lamentable, i only started a programming class a couple weeks agone with no feel before that, so thats why my construction sucks. thanks for the help

didnt know about that portable stuff, only now that ive researched it, ive found cin.become(); to exist meliorate. thanks.

shiftyape
Feb 23, 2013
48
0
10,580
0
  • #8
@shiftyape, please read the rules regarding posting of homework assignments: http://www.tomshardware.com/forum/244553-49-read-programming-assignment-assist

its non, dont worry

shiftyape
Feb 23, 2013
48
0
ten,580
0
  • #9
I may be wrong, only the likely cause is accessing index 39. It's zero-index and then they start at 0 and end at 38, not 1 - 39.

super helpful, thanks. practice i just extend it to forty then?

Thread starter Similar threads Forum Replies Date
L Apps General Discussion 1
ssmana Apps General Discussion vi
Lumia925 Apps General Give-and-take 4
A Apps Full general Discussion 3
Thousand Apps General Discussion 1
UItmaWepn Apps General Discussion 0
South Apps General Discussion 9
S Apps General Give-and-take ii
D Apps General Word ane
P Apps General Give-and-take 3
viveknayyar007 Apps General Discussion 0
shiftyape Apps General Discussion 18
C Apps General Discussion 3
shiftyape Apps General Discussion ane
R Apps General Discussion nine
j_a_k_e_24 Apps General Discussion 1
John_VanKirk Apps General Word five
R Apps Full general Discussion 1
fdd2blk Apps General Discussion iii
C Apps Full general Discussion 1
  • Advertising
  • Cookies Policies
  • Privacy
  • Term & Conditions
  • Topics

kinsellagream1959.blogspot.com

Source: https://forums.tomsguide.com/threads/why-is-this-c-program-not-working.363245/

0 Response to "Error Reading Characters of String Unable to Read Memory"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel