How do I append a number to the end of a string (and get a string back)? For example, I want to run a for() loop similar to: for(i = 0; i < num; i++), and for each pass through the loop I want to...
Type: Posts; User: BigFish21
How do I append a number to the end of a string (and get a string back)? For example, I want to run a for() loop similar to: for(i = 0; i < num; i++), and for each pass through the loop I want to...
How would you do this using iterators? I need to learn how to do it this way, I think this is what's confusing me from most of the insertion sort examples I've seen using arrays.
I want to use insertion sort to sort a vector containing some classes. Each class has a string name variable like this:
class myClass {
string name;
...
}
I want to sort the vector by...
use an iterator
Let's say I have a string s:
string s = "How are YOU doING toDay?"
I want to convert this string so that only the first letter of each word is capitalized (so I want it to be: "How Are You...
vart, that works! thanks. Just one more question about copy constructors in general: You can specify additional parameters for a copy constructor (in addition to the reference to same class type) as...
Well bClass[] is actually dynamically allocated with
bClass[i] = new aClass(arg1, arg2); looping through a for loop in a separate function (arg1 and arg2 are arguments to the constructor for...
Suppose I have a class like this:
class aClass {
char *ptr; // random variable, not important
int time;
aClass *bClass[5];
public:
aClass();
~aClass();
aClass(const aClass&...
Ok, I've encountered another problem in this program. So far I've implemented mkdir() and ls() that both work, however I've been trying for the past day to be able to do this: When the program first...
Ok I got this to work!:
(*(*funix).currentDirectory).subDir = (Directory**)malloc(3*sizeof(struct Dir *));
funix->currentDirectory->subDir[0] = (Directory*)malloc(sizeof(Directory));
...
Ahh ok, so I managed to dynamically allocate subDirs, but I'm getting an error when trying allocate subDir.name:
(*(*funix).currentDirectory).subDir = (Directory**)malloc(3*sizeof(struct Dir *));...
Ok got it.
Now with a question for actually creating directories with function mkdir():
When the user enters a mkdir command, I call the mkdir() function:
void mkdir(Funix *funix, int...
Ok so this isn't a structs question, but I've moved on to actually getting a command from the user. I want to store the number of arguments and also how many arguments. This is what I have now in...
Why wouldn't that work? You can do something like this:
char *str;
while (str != NULL) {
str = strtok(line, ":"); // <- this will store "somefile"
str = strtok(NULL, ":"); // <- now str will...
Thanks Elysia, for the casting I learned to not cast it either, but for this assignment we are supposed to compile it with g++ (I'm not sure why exactly..) and I always get an error if I don't cast...
Oh I see. I realize I made a mistake in my Directory struct though, the Permissions struct should not be defined in it like that, instead (I think) I want a pointer to an instance of the Permissions...
Hm yes that does seem to work, what does it do exactly? Is there another way of doing this? I only remember learning a little bit about the -> operator a while ago, don't remember much now. thanks
Oh, I see, stupid mistake. Thanks
So it works now when I want to access the Funix struct (i.e. (*funix).umask = 666), but I still can't access the Directory struct. I tried this:
...
So if I understand you correctly I first have to do this in init()?:
Directory *currentDirectory = (Directory*)malloc(sizeof(Directory));
(*currentDirectory).name = (char*)malloc(sizeof(char));
...
Oh my bad, yeah it is Funix sorry.
So I first do Directory *currentDir? How would I access it? (*funix).currentDir.name? I havent seen that before, that's probably wrong.
thanks!
For a programming assignment I have the following two structs: (sorry it's a bit long!)
typedef struct Dir
{
char *name;
struct Dir** subDir;
struct Dir* parent;
struct
{
For this program I have to write it seems I have to use a struct within a struct. I tried simply doing this:
typedef struct
{
...
typedef struct
{
...
...
Oh I see, yes rooms is declared "Room *rooms" in main(). thanks
In an example program my professor gave me that reads data from a file about rooms. For example the data file reads:
Bill Mueller
129450.93 4
2:300.5:Living Room
1:107.0:Bedroom 1...
I want to use fread() to read a binary file containing Passenger structs like this:
typedef struct
{
int ID;
char first_name[15];
char last_name[15];
int flight_nums[4];
}...