Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with inputting multidimensional string arrays....
#71
I don't really have a preference on either one of the methods. They both take up 12 lines of code.

I am really liking C++ more and more. I do have another question. If I have an array of strings how could I figure out how many different strings are in it?

The reason I need to know is because I pass a char **files to a function that mallocs everything with each string in the array the length of the biggest filename. So when I get back to the function that had **files in it, I don't know it's dimensions (how long the longest string is, and how many strings there are in the array).

I know that using a reference pointer passes through the function parameters for the number of files and biggest filename would work, but I kinda wanted something cleaner.

also, when you free an array of strings, is it nessacery to free each individual entry in the array, or could you just free the whole thing at once?
like this
Code:
for (i = 0; i < num_files; i++)    free(files[i]);
    free(files);
or like this
Code:
free(files);
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply
#72
The former.
am an asshole. Get used to it.
Reply
#73
using this function to return a scancode:
Code:
enum
{
  KEY_ESC     = 27,
  ARROW_UP    = 256 + 72,
  ARROW_DOWN  = 256 + 80,
  ARROW_LEFT  = 256 + 75,
  ARROW_RIGHT = 256 + 77
};

static int get_code (void) {
  int ch = getch();
  if (ch == 0 || ch == 224) ch = 256 + getch();
  return ch;
}

what would be the scancode for ENTER? I googled and everything says 28. When I use 28 in my prog nothing happens (though I am using a laptop...).
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply
#74
Enter has an ASCII value, getch returns such. Use "13".
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#75
how do you compare two char arrays to see if they are equal (ignoring the case)?
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply
#76
strcmpi, I think
Reply
#77
yep, that worked.

Sometimes in my program when I ask the user for input it automatically thinks enter was hit. I suppose that the keystroke for enter or return is still in the input stream. So I need to know how to check if there is something in the stream, and how to clear it. I know cin.ignore(1, '\n') works sometimes (when you know for a fact that there is leftovers in the stream), but if I call that and there isn't anything in the stream, it messes everything up.
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply
#78
Code:
fflush(stdin);

Will clear the stdin buffer, which is used for input. It works with scanf, gets and C stuff, I dunno if it will work with that cin/cout scary/evil stuff Wink.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#79
I really don't know what I did, but I got it working. I finally finished my first program (with a little help :lolSmile. How do you compile the release version of a program that needs no dlls or objs and uses optimizations (MSVC)?
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply
#80
wait a sec, bunk that. I'm not done (though I did finally get it to compile the release version). Is there any way to make DATA statements (like in QB) in C++?
am: "Where should I put this thing so that it doesn't hurt anyone we know or care about?"
Max:"Out the window, Sam. There's nobody but strangers out there."
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)