C/C++ :: Displaying Array Elements Inside Struct
Feb 13, 2015
How can I display the elements of an array inside struct something like this
struct ABC {
double a[3];}
void show( const ABC & x );
ABC x{18, 'W', { 1.1, 2.2, 3.3 }};
show(x); would output {18, ‘W’, {1.1, 2.2, 3.3}}
View 10 Replies
ADVERTISEMENT
Apr 22, 2014
#include <stdio.h>
#include <string.h>
#define MAX 22
struct inven {
int Iid;
double uprice;
int uoh;
char name[MAX];
[code].....
doesn't seem to want to display the disp* fucntions at all
View 2 Replies
View Related
May 21, 2013
This is for a class project. I am having trouble "pulling out" the last element in my array, shifting all the elements back then inserting that last value in the front. Then also displaying the array after the shift. here's my code.
#include "stdafx.h"
#include<iostream>
using namespace std;
[Code].....
View 3 Replies
View Related
Feb 1, 2015
I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.
#include <iostream>
#include <cstring>
using namespace std;
[Code]....
View 4 Replies
View Related
Dec 9, 2014
I've been working for some number of days on this code to take information about movies from both a file and the user, store the infos in an array of structs, and at the end, write all the info out to a file. I'm having some problems with an error message reading:
"prog.c:102:11: error: subscripted value is neither array nor pointer nor vector"
this error occurs in many lines (which I will label specifically below -- they are everywhere where I am trying to access/modify an individual element of a struct element of the array).
A few examples of where I am having the problems are lines:
39, 52-55, 70, 72, and 86 (and more of the same exact variety).
I am obviously rather systematically doing something wrong, but I am quite certain all of these are the exact same mistakes.
I pull up also 2 or 3 other errors, but I don't think they are related and should be able to fix them quickly once I work out this conundrum.
#include <string.h>
#include<stdlib.h>
#include <stdio.h>
int moviecount =0;
typedef struct{
int year;
[Code] .....
View 5 Replies
View Related
Dec 1, 2014
Let's say there is a document which stores data of exams of 3 subject. The document is in the below format:
Subject code [spc] Student code [spc] Exam score [endl]
Repeatedly, there are 100 data. E.g.
ENGL_S12 [spc] 000001 [spc] 90.5
ENGL_S12 [spc] 000005 [spc] 77.3
MATH_G22 [spc] 000502 [spc] 100
LATI_F11 [spc] 002005 [spc] 65.4
...
Now I have to write a function show_exam_descending(Data d, string subCode)
when I call show_exam_descending(d, "ENGL_S12")
the program will execute to show all the students' exam scores in ENGL_S12 in DESCENDING order...
For this to run, I have declared a struct Data:
struct Data {
string subjectCode;
int studentCode;
double examScore;
);
For the search, I have written a function before to load all the data from the document by using pointer and dynamic arrays. It works so well. What troubles me is the way to swap the elements (i.e. examScore) of different students in struct dynamic arrays. I am able to display all of them, but don't know how to swap.
View 8 Replies
View Related
Apr 4, 2014
Not Displaying tree elements. Here is the code. Want to know the error.
#include <iostream>
struct TreeNode
{
int number;
TreeNode* left;
TreeNode* right;
};
struct Tree
[Code]...
View 1 Replies
View Related
Aug 31, 2013
#include<stdio.h>
#include<iostream.h>
struct node {
int info;
struct node *next;
[Code] ....
I am getting runtime error in some cases. Sometimes the last input is printed. How to correct the code and display all elements in the linked list.
View 6 Replies
View Related
Jun 5, 2012
"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);
[Code] ....
These codes give these errors:
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
View 3 Replies
View Related
Sep 28, 2013
I have a file in which I have written a structure called "Record".
Here is the struct definition:
Code:
#define IDSIZE 10
struct Record{
char id[IDSIZE];
int score;
};
Here's the code where I wrote to the file:
Code:
Record record;
char* id = "H12345678";
int score = 50;
record.id = id;
record.score = score;
file.write((const char*)&record, sizeof(record));
}
Here's a screenshot of the file in windows: [URL].... To the left is the id, 9 characters. To the right, well I'm assuming that's the score that I wrote.
And here's the problem, reading from the binary file:
Code:
Record record;
fstream file(argv[1], ios::in | ios::binary);
if(!file){
cerr << "Could not open the file." << endl;
return 1;
}
char* id = new char[IDSIZE];
[Code]...
The ID reads perfectly. The score...always returns 0, despite that it should show "50".
View 4 Replies
View Related
Jun 23, 2013
while writing code i got a question. For example i created a class named as unit.
Think a simple game, and the unit class will belong the units.İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...
and should i use struct to group them? And how to can i use struct at the inside of class as private?
View 2 Replies
View Related
Mar 12, 2014
This is with Linux gcc
Code:
typedef struct _a
{
int id;
} a;
typedef struct _b
{
a my_a;
my_a.id = 1; // error: expected specifier-qualifier-list before "my_a"
} b;
I get error: expected specifier-qualifier-list before "my_a"
I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?
View 10 Replies
View Related
Aug 25, 2014
I want to have a function pointer inside a typedef struct but I get a segmentation fault when I run my code. Here's my code:
#include <stdio.h>
typedef struct Foo {
void (*bar)(int);
} Foo;
void func(int x) {
printf("display: %d
[Code] ....
View 2 Replies
View Related
Jul 22, 2013
Can typedef and struct be put inside a class like below?
Code:
class classA {
private:
typedef void(classA::*aFnPtr_t) (); //pointer-to-member function
struct strctA {
int a;
int b[100];
};
typedef struct strctA strctA_t;
typedef void (classA::*bFnPtr_t)(strctA_t*); //pointer-to-member function
...
}
View 8 Replies
View Related
Apr 24, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct info info;
[Code] ....
View 2 Replies
View Related
Jan 6, 2012
I got assignment at my school to display 2D array like this:
This is default array:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Now I have to print the default array like this:
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
I have tried some codes to do it myself but i had no success.
View 1 Replies
View Related
Apr 20, 2014
this is my original code:
#include <iostream>
#include<fstream>
#include <string>
using namespace std;
string display(string);
main() {
[code]....
here is what it does;it reads from a text file and converts the characters to ascii numbers and stores them in 1D array.what I am trying to is storing these ascii codes in 2D array.
View 5 Replies
View Related
Feb 23, 2014
I been for trying to create 5x5 2d array that
basically display first column, last column , and diagonally (like " N " display). but i cant get it to work.
this is what i have so far.
int _tmain(int argc, _TCHAR* argv[]) {
char Test[5][5];
for (int i = 0; i < 5; i++)
[Code]....
View 4 Replies
View Related
Jan 10, 2015
Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
View 1 Replies
View Related
Jan 21, 2013
Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.
View 6 Replies
View Related
Mar 11, 2014
My requirement is,
Read *.bmp image and displaying bitmap image with scrollbar in a MFC dialog application.
I was done using this
I was read the *.bmp image as a pixel data and stored by 2D Array,
Now i want to Display this 2D array as bitmap image with scrollbar separately in the same dialog. How can i display bitmap with scrollbar using 2D array?
View 10 Replies
View Related
Sep 27, 2013
I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :
1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
"
View 7 Replies
View Related
May 28, 2013
I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.
decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.
whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?
Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/
#include <stdio.h>
#include <stdlib.h>
[Code] ....
View 4 Replies
View Related
Jun 7, 2013
Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...
Code:
#include <stdio.h>
int main (void)
{
const char *pointer;
const char alphabet[] = "ABCDEFG";
pointer = &alphabet[5];
printf("pointing to %c of the alphabet
", pointer);
return 0;
}
Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.
View 5 Replies
View Related
Apr 6, 2014
Ive recently got into function pointers, i find that they can be quite handy for making your program very 'dynamic'.
However, the syntax is very confusing for what i want to do
This is what i want to do
I want to hold function pointers inside an array, but this array is dynamically allocated ( malloc, realloc, etc )
This is the current syntax ive come up with, but i dont think it is correct
void ( **drawFunc ) ( void*, SDL_Surface* );
View 2 Replies
View Related
Apr 18, 2013
class Hallway {
private:
//---------------------------------------------------------------
// DO_04: Declare a Light array of size MAX_LIGHTS
// Hint: look through the methods below to find the name to use
// for the array
//---------------------------------------------------------------
int numLights;
int lights[MAX_LIGHTS];
[Code] .....
I keep getting the error " this.lights[i] is not a struct or class and so you cannot use '.' " on line 34.
How am I supposed to define my lights[] array? I can't modify anything except directly after each comment block.
View 6 Replies
View Related