Hi! I was doing my exercise of C Language. In the exercise I was encountered by a question in which author says you to perdict the correct answer; I was uable to perdict it, so I compiled it to get the answer, the source code is this: #include <stdio.h> int main () { struct { int x, y; }s[] = {10, 20, 15, 25, 8, 75, 6, 2}; int *i; i = s; printf("%d", s[i[7]].x); return 0; } It yields this output: 8 I'm unable to understand why the answer is 8 whereas in my thinking it should be 15. …

Member Avatar
Member Avatar
+0 forum 2

Situation: My VBA program compiles, but fails at runtime when I try to access a specific method. It doesn't seem to matter whether I set the method up as a function or a property get. Here is the code fragment which calls the method: ****** Function roots() As Variant ' array of variant(string, double or ratio): real roots only Dim fs() As MPolyFactor Dim f As Polynomial Dim result() As Variant Dim nFactors As Integer, i As Integer traceIn "entered roots; me = " & Me.toString() & "; f = " & stringify(f) On Error Resume Next ReDim result(1 To …

Member Avatar
Member Avatar
+0 forum 1

Please bear with me. This is my first post. For some reason, I can only display the strings if I put the cout in the same loop. But since I have to separate addString() and displayAllStrings(), I can't do that. My displayAllStrings() keeps failing. BUT when I write a separate display method, nothing is displayed. Sometimes when I try editing that part of the code, I end up with 'subscript out of range' errors. void Class::addString(vector<string>database, vector<string>newItem) { for(int r=0;r<9;r++) { database.push_back(newItem[r]); //cout<<"\n"<<r<<": "<<database[r]<<"\n"; //This can display } void Class::displayAllStrings() { for(int t=0; t<database.size(); t++) { cout<<"\n"<<t<<": "<<database[t]<<"\n"; } } …

Member Avatar
Member Avatar
+0 forum 1

My professor asks me to program the Game Of Life with some required and I find unnecessary classes. But anyhow as I am coding and running the program midway I run into this problem void Life::setup_grid() { cout << "Size of Grid: " << grid.size() << endl; cout << "rows: " << rows << endl; cout << "cols: " << cols << endl; for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { if(cell == 'A') grid[i][j] = new ACell(); //I get "Expression: vector subscript out of range." here. else grid[i][j] = …

Member Avatar
Member Avatar
+0 forum 6

[CODE] vector<vector <vector<char>>> Sub; Sub[0][0].push_back(s[0]);Sub[0][0].push_back('\0'); Sub[0][1].push_back('\0'); [/CODE] I have the above code and it says "vector subscript insaccessible" for the assignments.What could the reason? Thanks in advance, Prasanna

Member Avatar
Member Avatar
+0 forum 4

So I always seem to encounter this error. I usually find some odd hackish fix for it but this time I'm having too much trouble. I'm basically trying to make a program which corrects words the user types in (similar to that of any modern phone). The function I'm posting below is an attempt to make a vector of vectors. I am associating every letter with it's neighbor keys. For example... If the user types in the letter 'A', I want a vector with the value 'A' to hold every letter that the 'A' key touches (Q, W, S, and …

Member Avatar
Member Avatar
+0 forum 9

The program takes a file with names and GPAs and sorts them in order of highest GPA to lowest using vectors. I cant seem to find out whats wrong with the code. Everytime i run it it says 'vector subscript out of range'. Can someone please help me? File: James 3.9 Margaret 3.5 Charles 1.2 Jennifer 4.0 [CODE] #include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; #define MAX 2000 void reverse(vector<string> str,int size); int getArray(vector<string> str, istream& in); void bubble(vector<string> str, int size); void printvector(vector<string> a); int main () { char filename [256]; vector<string> str; int size; …

Member Avatar
Member Avatar
+0 forum 3

Hey folks, i have a problem with a vector im attempting to program. There are no compile errors but during run time i get an error saying: "Debug Assertion Failed! Program:...filepath\GA.exe File:...include\vector Line: 779 Expression: vector subscript out of range" etc... I have tried stepping throught the program to no avail, it seems to run fine for the time im stepping through. This leads me to beleive that somewhere, something is either running out of memory or looping too far and trying to access a part of the vector that dosnt exist. Although i cant find anywhere obvious within the …

Member Avatar
Member Avatar
+0 forum 11

I have been messing with this program for my class for days now. I can get the program to run fine....I can get it to return highest value in list but i need it to return the month it occurs in. Here is the exercise as it appears in my book: 3. Rainfall Statistics Design a program that lets the user enter the total rainfall for each of the 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. and …

Member Avatar
Member Avatar
+0 forum 1

Hello/Hi, I m new to this pool of C. I wass just reading a book named "C TUTOR" this book is gr8.. but i cannot understand the subscripts of 2D arrays... I find them pretty hard.. Plz tell me wat exactly the below programme mean of suggest me some simple books or sites... Plz simple and breif ... Thanks in advance.. main( ) { int i,j; int big[8][8],huge[25][12]; for (i = 0;i < 8;i++) for (j = 0;j < 8;j++) big[i][j] = i * j; /* This is a multiplication table */ for (i = 0;i < 25;i++) for (j …

Member Avatar
Member Avatar
+0 forum 4

how can I write a super or sub char in string

Member Avatar
Member Avatar
+0 forum 3

The End.