I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.
I was wondering why, in C, the sizeof of a struct is larger than the the sum of all the sizeofs of it's members. It only seems to be by a few bytes, but as a bit of a perfectionist I fine this a bit annoying.
I'm having trouble figuring out how to find the size of an array program that involves "struct."
#include <iostream> using namespace std; struct d{ char* a; float b; int c;
[code].....
When I run this program, the output is 80(for my compiler). That would mean that each element in the array is 16 bytes but I don't understand how struct d is 16 bytes.
The definition of the struct doesn't show it but the documentation says that bRawData is variable length. sizeof(RAWINPUT) will not be the correct size when the data field is of RAWHID type so how do you allocate a variable with automatic storage type that has the right size for the entire struct? You can get a header that has the size for the entire struct but how do you actually allocate storage space for the data without using malloc? I've seen some example code that used a char array but that violates aliasing rules and there are also alignment issues with that approach.
I'd wrote a program to encrypt a message within a bmp file using my own structs and all for everything (yes, call me a ........head) The program works but for some weird ........ing reason I was forced to subtract 2 bytes from the header size to get the correct value. I've narrowed down the issue to my BmpFileHeader struct.
Here's a short program that demonstrates the issue:
Code: #include <stdio.h> #include <stdlib.h>
#define BYTE unsigned char #define WORD unsigned short #define DWORD unsigned long #define LONG signed int
[Code] .....
Tried with both gcc and TinyCC and got the same result so it doesent seem to be a compiler bug. Microsoft's structures though are giving the correct size, even though they have the exact same definition.
Microsoft's defines:
Code: // windef.h typedef unsigned long DWORD; typedef unsigned char BYTE; typedef unsigned short WORD;
Im having trouble creating a struct within a struct node. the program suppose to hold students firstname, lastname, and gpa in a node therefore creating my linked list. Line 26 keeps saying that cannot convert parameter 2 from 'studentType to std::string
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
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 just read and have known for a while that classes are private (members and inheritance) by default and structs are public. But my question then comes what if.. a struct inheriting from a class or a class inheriting from a struct?
how to split a file in equal size and when clicking on split button it split the files as well as encrypt split parts and the size information are automatically stored in groupbox and save all splitted files in folder.
struct example { int x; int y; }; int main() { example variable; variable.x = 1; variable.y = 2; map<example, int> something; something[variable] = 3; return 0; }
And I get a very long error message from the compiler. I tried using an enum as the key as well and that worked just fine, but I guess that's just the same as having an integer as the key. But anyway, what's the problem with this? Is there any way to make it work?
So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)
#include <stdio.h> struct database { int id_number; int age; float salary;
[Code] ....
When I compile, I get an error: test.c|18|error: incompatible type for argument 1 of 'printf'| note: expected 'const char *' but argument is of type 'float'|
I thought employee.salary is a float but the compiler expected 'const char'. How do I make this work?
I am working on a program which uses external hardware to acquire data. we have the option to use hardware from two different companies, each with it's own driver. However both do the same job. My program is meant to read data packets which are structured as:
I am programming my software so as t allow the customer to use the hardware of their choice. Simply select the card they are using and our program should be able to take care of the rest of stuff. I am using #ifdef directives to include the header for the corresponding hardware dll. Now I want to define my own data struct of the type:
I've been working on a path-tracer for some time, and all along I've used structs instead of classes for vectors and matrices. Today I changed all of them to classes instead, changing none of the actual function bodies themselves, and the results were miserable to say the least.
Here's a render form before the change: [URL] ....
And here's the same render after: [URL] ....
Why this is happening, considering that none of the actual function-bodies have been changed, except for what little is needed to make the change from class to struct.
So this is the last part of a program I've been working on for four weeks now. This question may be a tough one considering the amount of files included in the program.
The program is to read in a file of requests between two cities, read in a file of flights and cities that occur between the cities. It then checks to see if there is a path between the flights and output an itinerary. I have the correct itinerary outputting, but when attempting to output the associated flight number and price according to the city, I am getting odd data. How can I output the correct flight number and price associated with each flight on the itinerary.
I'll post out the output I am currently getting and the section where I am outputting the data. I'm sure I'll need to post more files so the program can be understood.
Don't want the code done for me, just a point in the right direction! I don't want to let this program defeat me!
Output: Code: Request is to fly from Atlanta to San-Diego.The flight itinerary is: Flight # From To Cost 10 Atlanta Chicago $134529069 10 Chicago Miami $134529069 10 Miami Dallas $134529069 10 Dallas San-Francisco $134529069 10 San-Francisco San-Diego $134529069 This function finds a path between cities. Code: bool flightMap::IsPath(string originCity, string destinationCity){ StackClass aStack, bStack; flightStruct flightRec; string topCity, nextCity; bool success; int index = 0;
I am working on an assignment identical to another post from a couple years ago, for reference here is the thread:
array of pointers to structures sorting addresses by zip code
They way it is written on that thread is almost identical to the way the teacher implied to have it done (only wrote part of the input block). But I am having an error:
When it gets to the output section it outputs then next name along with the zip code... I tried strncpy and strxfrm but both cause more problems than they did work.
The last part of the project is to have the output put out in order of least zip code to most zip code (00000<99999), so this is causing me a real problem and I do not see what exactly is making this happen.
Here is my code (we dont HAVE to use gets but professor suggested using it for this assignment, next lab is to rewrite this using files and fgets rather than I/O redirection):
I have not started the sorting code because I cannot get past this, but once I have proper zip codes I am sure I can make a sort function no problem.
I am using xcode with some breaks to read variables as various points and do not notice anything wrong until it makes it to the output functions, although this page briefly pops up between input and output functions when the breaks are up: