structure

C++ mutual class dependency

喜欢而已 提交于 2019-12-13 06:29:17
问题 I am writing a card game in C++. I have a player class, which handles the actions (i.e. selecting a card to lay). If the player is a human, it will use a GUI class , if it is a computer, it will use an AI class . In order for the AI class to make decisions, it needs to know some things about every player that change during the game, for example the number of cards on hand. Right now I store a player pointer for every player in a vector in the AI class. However, this leads to my problem, the

Converting string to float in C?

时光怂恿深爱的人放手 提交于 2019-12-13 04:44:59
问题 Right, So in my C program i have a function that takes a float value from file, and here i am trying to do the reverse, taking the string and turning it into a float. float PsSc = atoi(stock01[DataCount].defPsSc); I know my error, i assumed it would work for both integers and floats, it doesn't. I have tried float PsSc = atof(stock01[DataCount].defPsSc); and that doesn't work either. So, My question is: What can i replace my current line of code with to make it work? Input: 1.45 . Expected

Easiest way to return double from another class

倾然丶 夕夏残阳落幕 提交于 2019-12-13 04:06:39
问题 I wish to return a double from another class depending on input doubles. Any good links/examples to very simple project structure examples would be appreciated. Am I missing something in manifest. ie. activity 1 import com.example.app.utils.getRhumbLineBearingUtil; double tbearing = getRhumbLineBearing(alata,alona,alatb,alonb); double recipbearing=getRhumbLineBearing(alatb, alonb, alata, alona); Activity 2 import com.example.app.utils.getRhumbLineBearingUtil; double lattocbearing =

Allocating memory for a structure array inside another structure

好久不见. 提交于 2019-12-13 04:01:09
问题 I really don't know what the issue is here. The compiler says it's all okay, but when I run it, the executable crashes ( I believe it's a segmentation fault problem ). They say two minds are always better than one, so I hope you guys can find whatever I have missed. Okay, so it goes this way: I have 2 structures: struct _Color { unsigned char r,g,b; char *pchars; }; //typedef to Color in header file struct _XPM { unsigned int width; unsigned int height; unsigned char cpp; unsigned int ncolors

Program to generate iterations

纵然是瞬间 提交于 2019-12-13 03:35:28
问题 I have set myself a task to code this algorithm, however, since i haven't had a full experience in C, I was hoping there might be an easier method. Ok, Take 2 numbers, a , b We take the sum of these and add to the sequence, then add on the second term. So we get a , b , a+b , b For the next term, we take the 2nd and 3rd values (Before we did 1st and 2nd) and do it again. so we now get a , b , a+b , b , a +2b , a+b (continued) a+2b , b , a+3b , a+2b , 2a+3b , a+b This continues on until

How to search a specific node in a graph structure in C?

被刻印的时光 ゝ 提交于 2019-12-13 03:06:45
问题 Not that I have time to discuss this properly to reach a conclusion and adapt my code because the phase one (of three) of a school project is in 24hrs, but at least I need to know if I did the correct decision. I'm using linked lists and here's my structures: typedef struct sCity { int cityID; char *cityName; struct sCityLink *links; struct sCity *next; } nCity, *City; typedef struct sCityLink { City cityLinkParent; City cityLinkTo; struct sCityLink *next; } nCityLink, *CityLink; Basically, I

Can I make c++ code structure see each other? [duplicate]

强颜欢笑 提交于 2019-12-13 01:34:31
问题 This question already has answers here : self referential struct definition? (9 answers) Closed 3 years ago . Im not good at English.. sorry for example, struct structure1 { structure2 st; } struct structure2 { structure1 st; } It has incomplete type error How can I use this code?? It is work well in java but in c++ I think because top down process.. I wonder It has solution good work This is my real code It is part of graph algorithm struct Edge { Node destination; int capacity; int cost;

Assigning values to members of structures

删除回忆录丶 提交于 2019-12-13 01:03:14
问题 I am currently working on a project for a course in C programming and have run into a problem. I am still quite new to the language C but have experience programming Java. My program runs into a problem when I try to assign a value to a char * variable member of a struct . The code in question follows below: void ReadFile(ComponentType * Data, int * numEl, int * numNodes) { size_t index; FILE * dataFile; char * data; float * value; numEl = malloc(sizeof(int *)); numNodes = malloc(sizeof(int*)

summation values in structure in matlab

自作多情 提交于 2019-12-12 23:30:32
问题 I have a 3 -by- 3 -by- 3 struct, struct , with fields bit . In each field I have two values. I want to divide values of each field by a summation of values of each field in dimension 3 for example if struct(1,1,1).bit=[2, 3] struct(1,1,2).bit=[4, 5] struct(1,1,3).bit=[6, 7] my new struct values must be for example: newstruct(1,1,1).bit=[2/(2+4+6) , 3/(3+5+7)] newstruct(1,1,2).bit=[4/(2+4+6) , 5/(3+5+7)] newstruct(1,1,3).bit=[6/(2+4+6) , 7/(3+5+7)] 回答1: As it is MATLAB, you should possibly go

Guidance on Android file storage

我只是一个虾纸丫 提交于 2019-12-12 20:23:18
问题 I need to write an Android app that would download sounds from the internet for further use. Where should i store these sounds? Is Sqlite an option? And what's the best way to load and play these files? Thanks in advance. 回答1: I would recommend putting the files on the SD Card, if one exists. One thing to note, though, is that you should never hard code a path to the SD card. You would likely want to do something along the lines of: try { //Create handle to SD card drectory exportDirectory =