Hello, I work at the U.S. Department of Labor, on the Unemployment Insurance program. I am working on developing a new Benefit Financing model for the state of Oregon, and I am having an issue with passing a struct between mutiple .c and .cfn files( the .cfn files are for the C cursor screens). The srtuct in question foloews: extern struct{ double x[6][30]; double xtxy[6][5]; double b[6]; double bstde[6]; double tval[6]; double bset[3][6]; double stats[6]; double ajrsq,ystde,ymse,xtra1,xtra2,syy;}regrs_; The struct is declared first in the main .c module, bsyrhd.c, and is further defined in a .cfn called later, invxtx5.cfn. Compiling the …

Member Avatar
Member Avatar
+0 forum 4

I have the following struct definition: struct finfo { string filename; long fsize; bool operator() (finfo i, finfo j){return (i.fsize > j.fsize);} } fstruct; And the following vector definition: vector<finfo> fdata; In the code I use the following statement to sort the vector elements by fsize: sort(fdata.begin(),fdata.end(),fstruct); This works perfectly well, but how can I sort by the field "filename" when i.fsize = j.fsize ? (The vector is filled by reading directory information, and putting the filenames and filesizes in the appropriate fields in the struct. If the filesize is equal I want to sort the files alphabetically by file …

Member Avatar
Member Avatar
+0 forum 3

Okay. This weeks 'problem' is that I need to simulate a game. I have to make two singly linked lists which will contain a name of player, his attack (double/float) number and his defence number and so on for as many players as the user inputs. The point of the game is to try to break the other 'chain'. You do that by running into 'enemies' chain and trying to break it, you break it if your attack is greater then defence of two players that you are trying to separete. If you separate them you can pick one of …

Member Avatar
Member Avatar
+0 forum 8

I have a linear array of structs. These are constant structs and is a way of holding a simple table. Now though I need to add another "column" to the table (another member in the definition of the struct) and I'm wondering if I'd be better using a class rather than a struct. Since both structs and classes have constructors I'm wondering which is best to store fixed arrays of data?

Member Avatar
Member Avatar
+0 forum 4

Hi, I have such simple structure in unmanaged C++: struct Cam { char ip[16]; char login[16]; char pass[16]; char name[16]; }; and C# marshalled structure: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct Cam { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string ip; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string login; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string pass; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string name; } When I pass C# struct to C++ lib by function [DllImport("NVRLib.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void AddCameraStruct(Cam cam); ... Cam cam = new Cam(); cam.ip = "192.168.0.232"; cam.login = "admin"; cam.pass = "admin"; …

Member Avatar
Member Avatar
+0 forum 1

I have a void function that takes data from an ifstream, reads the first value, (which is an ID #), and compares that value against the ID# info from an array of records. If it's invalid, the rest of the line is ignored. If it's valid, it adds the hours worked to the hours worked field in an array of records. Here is what the input file looks like: 123 7.5 56 6.25 99 an invalid id 555 2.5 123 10.0 My issue is there is the possibility of multiple entries for the same ID# and for the life of …

Member Avatar
Member Avatar
+0 forum 3

I'm not sure if I'm freeing the memory correctly. I have the following struct and I'm trying to free the pointer in it. typedef struct RECORD { char* name; int score; }RECORD; In my main function I have an array of this struct, therefore I'm using a loop to free it. for(index=0;index<50;index++) { free(report[index].name); report[index].score=NULL; } But then, to test if it worked I print the whole array and I get the following, ╪K3 0 Donald Knuth 0 0 Adele Goldberg 0 0 Brian Kernighan 0 Linus Torvalds 0 ╪K3 0 Grace Hopper 0 ╪K3 0 Peter Norton 0 Bill …

Member Avatar
Member Avatar
+0 forum 2

Hi. Im trying to write a simple deck of cards program. I am having difficulty in expressing my integer deck into a printable form. The deck is generated as this: 00102030405060708090100110120011121314151617181911011111210212223242526272829210211212203132333435363738393103113123 The leading numbers assign to suits and the following number assign to card rank. Basically how can I convert this to print in the form: Card 1: Ace of spades Card 2: 2 of spades Card 3: 3 of spades etc; Could I use if statements and BREAKS to change the ints into strings? Perhaps a char value for suit would be better.. Any suggestions? Any help would be …

Member Avatar
Member Avatar
+0 forum 7

So, I'm using allegro game programming library. Before I move on to bigger and better things I wnat to get a handle on pointers. Specifically with things like structs, linked lists and maybe binary trees in the future. I posted a program that uses a linked list to keep tracks of a variable number of objects on the screen. GDB tells me it fails in the main also, the new style of posting is kinda buggy, for example I can move the cursor past the program code. gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: …

Member Avatar
Member Avatar
+0 forum 3

I wrote this program... Just gave a try!! i got a problem with searching a string in file.. the **"checkp"** used in the login function, returns a value **"1"**, whereas it must return a value **"0"** Hence my program fails... what i felt is, the file i'm opening, **"web_reg.txt"**, in that, extra spaces are coming... Does anyone knows, to sort this out???? Please help me!! please check it out in your PC's. Thanks a lottt **The code is as following:** #include<conio.h> #include<stdio.h> #include<string.h> struct web { char name[30],pass[30]; }w; int n; void login(void); void reg(void); void main() { clrscr(); printf("\n\n\n\n\n\t\t\t\tWELCOME …

Member Avatar
Member Avatar
+0 forum 11

iam trying to store all the data in to a struct so i can change it later. //this data is in file abc 1 11 22 def 2 33 ghi 0 22 11 33 asd 2 i was planing on making a array of structs. so 1st line will have one struct. 2nd line will have 2nd struct. struct node { char *alp; int x; int ar[]10; }; int main() { int i = 0; char *array[20]; struct node buff {NULL, 0, 0000000000}; while(read one line(LOOP) fscanf()) - array[i] = buff->alp = abc; - array[i] = buff->x = 1; - …

Member Avatar
Member Avatar
+0 forum 5

Hello everyone, I have a program that intends to create a doubly linked list of structures, using the following header (q1.h): [CODE=c]typedef struct lNode* ListNodePtr; typedef struct lNode { char* string; ListNodePtr next; ListNodePtr prev; } ListNode; [/CODE] This is my implementation: [CODE=c]#include "q1.h" #include <stdio.h> #include <stdlib.h> #include <string.h> ListNodePtr tail = 0; ListNodePtr newNode(void); ListNodePtr addNode(ListNodePtr h, char *w); void printList(ListNodePtr h); void deleteNode(ListNodePtr h, char *w); ListNodePtr newNode(void) { ListNodePtr n; n = (ListNodePtr)malloc(sizeof(ListNode)); n->prev = 0; n->next = 0; return n; } ListNodePtr addNode(ListNodePtr h, char *w) { ListNodePtr a; if (h == 0 && tail …

Member Avatar
Member Avatar
+0 forum 30

Hi, I have a task to perform which all to do with the smurfs, reading from a file and doing some simple stuff to it. The last part I need to do is print out a list of all smurfs and their corresponding role in alphabetical order. I am hoping I can do this using the qsort function but this is giving a segmentation fault. I have attached my code below: [CODE] #include <stdio.h> /*Required for file operations*/ #include <string.h> /*Required for strlen etc*/ #include <stdlib.h> /*Required for Malloc,Free, etc.*/ /*-----------------------------------Declarations----------------------------------*/ FILE* fp; /*Declare the file pointer*/ char str_read[50]; char …

Member Avatar
+0 forum 0

Hey everyone, I wrote some code to create a deck of cards, described the deck and randomly deals 5 cards. First, I want to let everyone know that this is homework for my C-II college class, so I am not looking for any answers, but solutions or guidance in figuring out what I am trying to do. What I want to do with this deck of cards is to shuffle the deck and then deal 5 cards, while not dealing the same cards in that hand. IE: Program deals 5 cards. The 5 cards are as follow (I actually ran …

Member Avatar
Member Avatar
+0 forum 6

Hello there..i'm trying to implement a tree in C#..the basic node structure is give below [code] struct node { public int _x; public int _y; public int _cost; public node _parent; public pos(int i, int j,int cost,pos parent) { _x = i; _y = j; _cost = cst; _parent = parent; } } [/code] I get the following error when i try to compile : 'node' causes a cycle in the struct layout This was the way we used to make a tree in C++..but it's confusing in C#..could anyone please enlighten me?? Any help would be appreciated.

Member Avatar
Member Avatar
+0 forum 2

I am new to structs and I am trying to sort an array of structs but I can't seem to get it to work, I can't figure out what I am doing wrong and any assistance would be very much appreciated! [CODE]#include <iostream> #include <fstream> #include <iomanip> using namespace std; const int SIZE = 30; struct people { string last; string first; string telephone; }info[SIZE]; void input_data(ifstream& in_data, people info[]); //void sortValues(people info[]); void bubbleSort(people info[]); int main(){ int x; ifstream in_data("directory.txt"); if(in_data.fail()){ cout << "Can't open the file\n"; cin.get(); return(0); } input_data(in_data, info); //sortValues(info); bubbleSort(info); cout << info[0].last << …

Member Avatar
Member Avatar
+0 forum 4

i am receiving a struct from the switch: [CODE]/* Packet received on port (datapath -> controller). */ struct ofp_packet_in { struct ofp_header header; uint32_t buffer_id; /* ID assigned by datapath. */ uint16_t total_len; /* Full length of frame. */ uint16_t in_port; /* Port on which frame was received. */ uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */ uint8_t pad; uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word, so the IP header is 32-bit aligned. The amount of data is inferred from the length field in the header. Because of padding, offsetof(struct ofp_packet_in, data) == sizeof(struct …

Member Avatar
Member Avatar
+0 forum 2

Hello guys, just wondering why my program crashes when I try to delete a struct from my array. I'm trying to code so that the user searches for a student via a student ID, then opt to delete the searched student's record. I thought I got it right and the search works fine, but it crashes when I opt to delete the student's record! I know it's due to the actual deleting part in my code. Here's my whole code: [CODE]#include <iostream> #include <iomanip> #include <string> using namespace std; void clrscr() { system("cls"); } void pause() { system("echo.");system("echo.");system("pause"); } void …

Member Avatar
Member Avatar
+0 forum 10

Hi, I am using WinSock library for sending data over network, and I have a problem. I know how to send data in one struct and receive it on the other side, because there is constant size of structure. But what if I have more structures, each one with different size? Now I have one struct that contains locations of players and other with in-game messages. When I am about to receive struct, I don't know which one is being sent. Is there a "trick" how to do that? Thanks for help.

Member Avatar
Member Avatar
+0 forum 7

Howdy, I have a few questions regarding the use of ctime within a class. I followed the example on [URL="http://www.cplusplus.com/reference/clibrary/ctime/strftime/"]http://www.cplusplus.com/reference/clibrary/ctime/strftime/[/URL] When the program is like this, it works: [CODE] #include <ctime> #include <iostream> using namespace std; int main(){ time_t current_seconds; current_seconds = time(NULL); //Fills current_seconds with the number of seconds since January 1, 1970 struct tm * timeinfo; char buffer [80]; time (&current_seconds); timeinfo = localtime (&current_seconds); strftime (buffer,80,"Event Date: %x",timeinfo); //Modifies timeinfo into a user readable format puts(buffer); // Posts the string "buffer" strftime (buffer,80,"Event Time: %X %Z",timeinfo); puts(buffer); return 0; } [/CODE] [B]Question 1[/B]: Is it possible to …

Member Avatar
Member Avatar
+0 forum 3

Hi, I'm a beginning C++ student and have an assignment to dynamically create an array of a struct to store students' first names, last names, and test grade scores, and then pass it via pointer to a function that will sort the grades and names in ascending order. I wrote a function that finds the lowest numeric grade score of the pointer array of struct, puts it in the first (0) index position, and then puts the numeric value that was in the first (0) index position in the index position that was formerly occupied by the newly found lowest …

Member Avatar
Member Avatar
+0 forum 3

i create small application in struts but it give me following error : SEVERE: Servlet.service() for servlet jsp threw exception java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491) at org.apache.struts.util.MessageResources.<clinit>(MessageResources.java:57) at org.apache.struts.taglib.html.FormTag.<clinit>(FormTag.java:93) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:126) at org.apache.jsp.Index_jsp._jspx_meth_html_005fform_005f0(Index_jsp.java:109) at org.apache.jsp.Index_jsp._jspService(Index_jsp.java:87) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) //////////////////////// I include commans-logging.jar but still it gives me error pls anyone can help me! …

Member Avatar
+0 forum 0

Hi guys, Is there a difference between these two: struct->variable struct.variable ?

Member Avatar
Member Avatar
+0 forum 3

After a few months of learning and practicing C++ with the book C++ Primer Plus through Chapter 7, I decided to do myself a little simple program. I started with the decision to try splitting my program into multiple files, and I decided to collect all shared declarations/definitions (*) into header files, and that is where the problem started. The first header file created (let's call it headerFile.h), the one I'm working on, has declarations/definitions like these: [CODE]enum QUALITY {QUALITY_1, QUALITY_2, QUALITY_3}; enum QUANTITY {QUANTITY_1, QUANTITY_2, QUANTITY_3, QUANTITY_4}; struct myStruct { int myInt; int myOtherInt1, myOtherInt2; QUALITY myQuality; QUANTITY myQuantity; …

Member Avatar
Member Avatar
+0 forum 5

I have this struct for an item in a to-do list [code=c] struct Task { char description[TASK_DESC_SIZE]; /* description of the task */ int priority; /* task priority */ }; [/code] i'm just not sure how to alter the description while making a task using this [code=c] TYPE createTask (int priority, char *desc) { struct Task* t = (struct Task*)malloc(sizeof(struct Task)); t->description = *desc; t->priority = priority; return *t; } [/code] I would love to know how to change the description.

Member Avatar
Member Avatar
+0 forum 1

Hello, I'm new to this thread but have referenced to it before many times. I have finally joined thanks to all the great responses I have read in the past. Okay, I recieved an assignment which is as follow... "Declare a dynamic array of Person to store the information of each student. Implement a simple user interface that allows the enduser of your program to: (1) type in the total number of students at runtime from the keyboard; and (2) provide the specific value of every data member for each student. Then implement the counting sort algorithm to sort all …

Member Avatar
Member Avatar
+0 forum 11

[CODE] #include <stdio.h> #include <string.h> typedef struct { char firstName[50]; char lastName[50]; int age; }Person; void ModifyPerson(Person*); int main() { Person person; strcpy(person.firstName, "firstName"); strcpy(person.lastName, "lastName"); ModifyPerson(&person); printf("First Name=%s\nLast Name=%s\n",person.firstName, person.lastName); system("PAUSE"); } void ModifyPerson(Person *p1) { //This doesn't modify the original variable declared in main function Person person = *p1; strcpy(person.firstName, "Modified1"); strcpy(person.lastName, "Modified1"); //This does modify the original person variable strcpy((*p1).firstName, "Modified"); strcpy((*p1).lastName, "Modified"); } [/CODE] In the above code, the first 3 lines in method ModifyPerson fails to modify the original "person" variable declared in main method. The changes made by the first 3 line of code …

Member Avatar
Member Avatar
+0 forum 5

Hello DaniWeb, I am pretty new to this community and overall to the C++ language. Not so long ago i've decided to learn C++. Anyways the problem is: I am trying to make a simple calculator, its very easy my problem is i am trying to advance my knowlege about the structure so i was trying to make a calculator using only structure based variables, my question is: When i take a normal integer variable for example: [CODE=c++]int x,y,z; z=x+y;[/CODE] would compile correctly but if i would make a structure called database example: [CODE=c++] struct database{ int x,y,z}; database get; …

Member Avatar
Member Avatar
+0 forum 2

Problem 1: I was wondering if it's possible to add for example the struct below into a binary tree: [CODE=c] struct Appoint { string place; string title; int hour, minute; int durationHr, durationMin; }; [/CODE] I want the above struct to be sorted in the binary tree by hour and minute. From what i've been looking on the internet though it seems that only one kind of variable can be entered in a binary tree? Is it not possible to add after the int hour and minute into the node of a binary tree with the rest of the Appoint …

Member Avatar
Member Avatar
+0 forum 5

I am very new to development and have been sinking my teeth into C#. I have an application that was written in C++ which is out of my depth, and I was wondering if someone could explain how I would recreate this in c#. The application sends message to linux service via a socket connection. The message is in the form of a struct: [CODE] struct alert { unsigned short size; unsigned short signature; unsigned short bperiod; unsigned short bduty; unsigned short svolume; unsigned short stone; unsigned short sfrequency; unsigned short speriod; unsigned short sduty; }; [/CODE] This app was …

Member Avatar
Member Avatar
+0 forum 2

The End.