C :: How To Get Index Of Structure Elements
Apr 9, 2013
I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:
Code:
typedef struct gg{
int id;
int value;
}
[code]....
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?
View 7 Replies
ADVERTISEMENT
Jun 17, 2013
I need to sort the elements in a 2d array by their index (starting from 1) for example:
Code:
1 5 3
4 7 8
4 10 2
10 is the biggest element and its index is 32, after 10 comes 8 with index 23 etc etc...
Looking for examples for two orders ... By descending and ascending order...
View 5 Replies
View Related
Apr 22, 2013
Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4
Code:
int element[8]={2,2,0,3,3,0,1,2};
col=4;
int rr;
int qq=0;
for (rr=0; rr<col;rr++){
join_tmp[qq]=rr;
while ((element[rr]== element[rr+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d
",join_tmp[qq]);
rr++;
}
qq++;
}
Code:
//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}
Code: I want input like
10
2
3
Instead i get
10
2
34
how can i fix it so it will only iterate to the specific range?
View 2 Replies
View Related
Mar 7, 2014
Code:
const MenuData breakfast[NUMOFBREAKFASTITEMS] = {
{"Egg Breakfast", "Two eggs with a side of bacon and two slices of toast.", "", "2 Eggs, 2 Toats, 2 Bacons", "", 250.00},
{"Pancake Breakfast", "Three Buttermilk pancakes served with butter and syrup.", "", "Three Pancakes, Butter, Syrup", "", 200.00},
[Code]....
What I'm trying to do is call the printReceipt function in the main, but I'm doing it wrong. Here is my attempt.
Code:
printReceipt (const MenuData menu[], qty, info)
I've tried it many other ways but I keep getting an error. I tried researching it on the internet, but I don't get much info.
View 14 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
Dec 7, 2014
Why doesn't this compile?
struct hi(){
void other();
}histructure;
void hi::other(){
std::cout << "Hi!" << std::endl;
[Code] ....
Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
View 3 Replies
View Related
Oct 7, 2014
Is it possible to assign a value to structure member inside the structure.like.....
struct control{
char tbi:2 =0;
char res:1 =0;
};
View 6 Replies
View Related
Mar 17, 2013
how I can create a structure that pointing to another different structure. And also passing structure to function.
View 3 Replies
View Related
Apr 17, 2014
I was trying to debug a code which was behaving in an abnormal way
Code:
#define NOOFELEMENTS 32
unsigned char array[NOOFELEMENTS];
unsigned char array1[23];
init() {
for(i=0;i<=32;i++)
{
array[NOOFELEMENTS] = 0
}
}
I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.
View 4 Replies
View Related
Sep 9, 2014
I am trying to get the index of a value by inputting the value:
For example if i have
int arr[5]={22, 85, 58, 78, 69};
indexOfItem(arr, 78);
and have the output be:
the index of the item is: 3
View 3 Replies
View Related
Dec 16, 2013
If i have current index and row/columns count how do i get on which row and on which column index is individually?
This is what i have tried, but column index is incorrect:
#include <iostream>
int main()
{
int rows = 5;
int colm = 6;
int inx = 12;
int rowInx = inx % rows;
int colInx = inx % colm;
std::cout << "row: " << rowInx << std::endl;
std::cout << "col: " << colInx << std::endl;
return 0;
}
View 4 Replies
View Related
Jun 27, 2014
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter7Problem13
[Code] .....
I keep getting an out of bounds error in my code
I'm suppose to enter number of orders then enter those orders then calculate a discount and net price display the orders, discount, net price then the totals at the bottom ....
View 5 Replies
View Related
Dec 9, 2013
I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.
Prototype should be something like
int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements
I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.
View 3 Replies
View Related
Sep 6, 2013
How can I use one index to iterate between all the values
for example:
//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());
//then the standard method to iterate is:
for(vector<typeA>::Size_type i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}
the other way, use int,
//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());
//then the standard method to iterate is:
for(int i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}
none of above make me feel formal...
View 7 Replies
View Related
May 21, 2014
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mind_Puzzle {
public partial class Form1 : Form
[Code] .....
When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".
The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe
View 1 Replies
View Related
Oct 27, 2014
I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).
Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].
View 3 Replies
View Related
Nov 5, 2014
I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?
Code:
1
2
3
4
5
6
7
8
char * GetValueAtIndex(char * const c, int index)
{
int i = 0;
char *p = c;
while (i++ != index)
p++;
return p;
}
View 2 Replies
View Related
Nov 22, 2014
Im problem with parsing. I read file line by line and i store another class bu when i parse the line last word gone example "I study algebra and discrite math" math didnt store.Why ? i want to calculate index section for document how can i solve this problem??
Code:
void DocumentIndex::parse(){
size_t pos = 0; //position
pos =line.find(" ");
while( ( pos = line.find(" ") ) != std::string::npos )
{
[code]....
View 1 Replies
View Related
Oct 12, 2013
my question is located as a comment beside the last printf ! ? check the comment near the last printf the comment is ==>here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?
Code:
#include <stdio.h>
#define N 30
#define n 100
[Code]....
here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?
View 1 Replies
View Related
Jan 10, 2015
Here's my code
bitIndex = 5;
Code:
bool getBS(PBitSet _this, int bitIndex) {
if(_this->bits & (1 >> bitIndex))
return true;
else
return false;}
I want this code to return the value of the bit at position bitIndex. It can be either false or true. The problem is, that it always returns false, even thought I enter 16 as my number, so the 5th bit should be true.
0000|0000 = 0
0001|0000 = 16
View 10 Replies
View Related
May 3, 2013
I am storing info in a vector but I want to store certain info at a particular index. I am new to using vectors and am unsure about have to do this. I am aware of the insert method but am confused on how to use it to store at a particular index.
View 1 Replies
View Related
Apr 9, 2013
Task: - Write a function `index` that converts an int from 0 to 5 into its word. (It should take an int and return a string.)
0 -> "zero"
1 -> "one"
2 -> "two"
3 -> "three"
4 -> "four"
5 -> "five"
anything else -> "other"
#include <iostream>
using namespace std;
string index(int x) {
if(x=0)
return "zero ";
else if(x==1)
[Code] .....
It compiles but doesn't print anything.
View 4 Replies
View Related
Feb 9, 2013
I am new in c++ and I am having difficulties with finding values in two vectors. Basically, I have two constant integer vectors u and v . They have the same length. I would like to select all the values in u and v, that respect those statements:
u>= x1 & u<= x2 & v>= x3 & v<= x4
x1, x2, x3, x4 are predefined integers.
Below is the code i use to do that in Matlab:
idx = find(u>=x1 & u<=x2 & v>=x3 & v<=x4);
A=u(idx);
B=v(idx);
But how to translate that in c++.
View 6 Replies
View Related
Dec 7, 2014
Design and implement the class myArray that solves the array index out of bound problem, and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:
myArray<int> list(5); // Line 1
myArray<int> myList(2,13); //Line 2
myArray<int> yourList(-5,9); // Line 3
The statement in Line 1 declares list to be an array of 5 components, the component type is int, and the componentst are : list[0], list[1]…list[4]; the statement in Line 2 declares mylist to be an array of 11 components, the component type is int, and the components are: mylist[2],…mylist[12].
This is what I have so far:
#ifndef H_myArray
#define H_myArray
#include <iostream>
using namespace std;
template <class myArray>
class myArray
{
public:
private:
return 0;
};
#endif
View 1 Replies
View Related
Oct 10, 2013
I have been learning c++ for about 1 month. So my problem is that suppose i have array[6]={10,-1,3,54,2,12}
I want to fill new array with {1,4,2,0,5,3}
because -1 is the lowest and its index is 1
2 is the lowest and its index is 4
3 is the lowest and its index is 2
10 is the lowest and its index is 0
12is the lowest and its index is 5
54 is the lowest and its index is 3
I want to sort from lowest to highest but using the index value. Here is what i have but the output i get is {1,4,2,4,5,5}
1,4,2 is right but then its wrong.
#include <iostream>
using namespace std;
void swap(int& v1, int& v2);
int main() {
const int size = 6;
int arry[6]={10,-1,3,54,2,12};
int sortedArry[6];
[Code] ....
View 1 Replies
View Related
Feb 12, 2014
I have problem with find the index of the following array.
int minimums[2]={201,201};//first initialize both to greater than maximum allowed
for (int index = 0; index < 200; index++) {
if(find_array[index] < minimums[0]) {
minimums[0] = find_array[index]; //Lowest number
[Code]....
View 14 Replies
View Related