Hola code gurus, I’m wondering if there’s a way to use a string to access a specific item in a matrix of int[X]. I have a program which uses enums as iterators to reference a large amount of data. To select an item in the matrix, the user will enter a string, which is also an enum, which also must serve as an iterator for something in the matrix. Here is a toybox example: #include <iostream> #include <string> using namespace std; enum NyNumbers { First, Second, Third, Forth, LAST_VALUE }; int main(int argc, char* argv[]) { int Matrix[LAST_VALUE] = { …

Member Avatar
Member Avatar
+0 forum 3

Hi everyone, I’m Pete, moderately-experienced C++ user who is always looking for better ways to do things. Let me ask you guys about a problem I’ve scratching my head over lately. Suppose I’m writing a program designed to simulate a large company. I’m interested in tracking each company employee by the location where they work. This company has perhaps a thousand different locations: [CODE]class Employee { public: AccessorFunction1(); // does something AccessorFunction2(); // does something different AccessorFunction3(); // does something completely different protected: // Some data }; class Company { public: void OrganizeLocation(int a); protected: vector<Employee*> LocationA; vector<Employee*> LocationB; vector<Employee*> …

Member Avatar
Member Avatar
+0 forum 3

Hi everyone, I'm a moderate-level C++ programmer who is a little rusty at the moment. I've got an object question which is driving me nuts. I'm sure this is a C++ 101 level question, but for the life of me, I can't recall the solution. Basically, I've got one object which has to access private data in another object... and can't. Here's the specifics: I'm writing a little war game program where players deploy units (soldiers, tanks, planes, etc.) onto a gameboard. Players and Units are modeled as objects: [CODE]class GameUnit { public: string GetName() {return Name;} protected: string Name; …

Member Avatar
Member Avatar
+0 forum 7

Hi everyone, I'm a moderately experienced C coder trying to figure out the [B]execve()[/B] command. Here's the basic problem: My program takes a command from the user, loaded into the string UsrCmd. The string is tokenized and each token is loaded into ParaArray[]. Then ParaArray[] is used as arguments to call execve(). I think I also pass in the user's environment variables with envp[]. But here's the problem: If the user inputs a command without the full path to that command, execve() cannot find the associated system call and fails. It is obviously too cumbersome to ask the user to …

Member Avatar
Member Avatar
+0 forum 1

Hi everyone, I'm a moderately experienced C++ programmer who's trying to do a little socket work. Don't ask why, but I'm to write a program which, when activated, sends an HTTP POST request to a remote end server. The socket part of the work is done and successfully tested; all I have to do is get the HTTP header exactly right. Unfortunately, the resources I've consulted online aren't that helpful and I can't tell where I'm screwing up the header. Can someone quickly spot the error or recommend a solid resource which will really detail what I want to do? …

Member Avatar
+0 forum 0

Hi everyone, I have a "This should be simple!" kind of problem. I need to do a little socket programming on a SunOS machine. I went back to an old school assignment I did years ago, cut-n-pasted that code, intending to basically cannibalize it for the program I need to write now. Trouble is, my compiler chokes on the socket-specific terms like getaddrinfo() or inet_ntop. Here is the output when I try to compile: ---------------------------------------------------------------------------- [CODE]bash-3.00$ g++ Main.cpp Undefined first referenced symbol in file getaddrinfo /var/tmp//ccCpuGRv.o freeaddrinfo /var/tmp//ccCpuGRv.o inet_ntop /var/tmp//ccCpuGRv.o gai_strerror /var/tmp//ccCpuGRv.o ld: fatal: Symbol referencing errors. No output written …

Member Avatar
Member Avatar
+0 forum 2

Hi folks, General question here... I'm writing a program which reads a ton of source data, crunches the numbers, and outputs a few nice summary reports. The source data is a lot of individual records: [B]00001,Item1,Item2,Item3,Item4,Item5,... 00002,Item1,Item2,Item3,Item4,Item5,... 00003,Item1,Item2,Item3,Item4,Item5,...[/B] Originally, I created an object called "Record," which stored each Item. But I ran into serious trouble when I realized there are literally [B][I]MILLIONS[/I][/B] of records. My machine simply doesn't have enough system memory to handle the load. So I need a completely new approach to this problem. Someone mentioned to me that my program should learn about these records by creating …

Member Avatar
Member Avatar
+0 forum 2

Hi everyone, I'm a moderately experienced C++ programmer working on code which must do the following: (a) Import data from a lot of little CSV files (b) Load that data into various objects (c) Do stuff with that data The code I've written does (a), (b), and (c) pretty well, but I've noticed a problem with (a), which I want to ask you guys about. Suppose I have 1000 source files. My program successfully processes Files #1 through #500. But when it reaches File #501, my program chokes and seg faults, and I automatically lose [I][B]ALL[/B][/I] the data I've collected. …

Member Avatar
Member Avatar
+0 forum 4

Hi everyone, I'm a relative beginner to writing UNIX scripts. In the past, I've been able to hack together simple scripts. Now I need a script which a little more complex than I'm used to, and I really need help. I'm up against a tight deadline and am growing desperate, as I can't seem to find a solution either on the web nor in my UNIX programming book. Here's the problem: I'm on a SunOS system. On the machine, I have a large number of files scattered across a vast directory structure. I have to copy all those target files …

Member Avatar
Member Avatar
+0 forum 2

Hi everyone, I'm a moderately experienced C++ programmer and a network engineer. I’m having a weird problem with using an array of vector<char *>, which I’ve never tried to work with before. I’m working on a program which does the following: 1. Inputs and parses a file called [B]PREFIX_FILE[/B], which contains all the prefix information on my network. 2. For every line, extracts the first token as a string and the second as an int. The value that int will always be from 0 to 32. (33 total) 3. The program creates an object called [B]MaskObject[/B], which is essentially just …

Member Avatar
Member Avatar
+0 forum 5

Hello everyone, I’m an intermediate-level C++ programmer grappling with a fairly rudimentary problem. I’m creating a C++ object called FruitCart; FruitCart contains a number of integers categorizing the numbers of individual fruit in the cart. I also need FruitCart to contain accessor functions so other functions can set, retrieve, and print the fruit values. Here’s what I have so far: [code] -------------------------------------------------------------------------------------- class FruitCart { public: // Constructors FruitCart(); ~FruitCart(); // Accessors void SetApples(int a) {Apples=a;} int GetApples() {return Apples;} void PrintApples() {cout<<Apples;} // Need accessor functions like the above for all kinds of fruit protected: int Apples; // Number …

Member Avatar
Member Avatar
+0 forum 3

The End.