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;
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;
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;
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.
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.
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".
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?
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 ?
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.
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
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?
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 :
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 */
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.
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.