Advertisement
Terrah

Untitled

Oct 16th, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include <string>
  5. #include <time.h>
  6. #include <iostream>
  7. #include "conio.h"
  8. using namespace std;
  9.  
  10. #define TESTSIZE 10
  11.  
  12. void FillWithTestData(int nth, char * buffer) {
  13.  
  14.     const char * data;
  15.  
  16.     switch (nth % 10) {
  17.  
  18.         case 0:
  19.             data = "pink panties";
  20.             break;
  21.         case 1:
  22.             data = "blue panties";
  23.             break;
  24.         case 2:
  25.             data = "yellow panties";
  26.             break;
  27.         case 3:
  28.             data = "red panties";
  29.             break;
  30.         case 4:
  31.             data = "black panties";
  32.             break;
  33.         case 5:
  34.             data = "teal panties";
  35.             break;
  36.         case 6:
  37.             data = "gray panties";
  38.             break;
  39.         case 7:
  40.             data = "white panties";
  41.             break;
  42.         case 8:
  43.             data = "magenta panties";
  44.             break;
  45.         case 9:
  46.             data = "invisible panties";
  47.             break;
  48.         default:
  49.             data = "striped panties";
  50.             break;
  51.     }
  52.  
  53.     strcpy(buffer, data);
  54. }
  55.  
  56. void main() {
  57.  
  58.     // Allocate the *array* to store our strings in
  59.     char ** strings = new char*[TESTSIZE];
  60.  
  61.     for (int n = 0; n < TESTSIZE; n++) {
  62.  
  63.         // Allocate 255 bytes for a string
  64.         strings[n] = new char[255];
  65.     }
  66.  
  67.     // At this point I now have an array of TESTSIZE that contain a pointer to an array of 255 chars each
  68.  
  69.     for (int n = 0; n < TESTSIZE; n++) {
  70.  
  71.         // Fill out some test data
  72.         FillWithTestData(n, strings[n]);
  73.     }
  74.  
  75.     // And now I have TESTSIZE strings that contain test data
  76.     // So I'll print it out:
  77.  
  78.     for (int n = 0; n < TESTSIZE; n++) {
  79.  
  80.         cout << n << ": " << strings[n] << endl;
  81.     }
  82.  
  83.     // Now I wanna deallocate said data you'll need to deallocate everything you created with new
  84.     for (int n = 0; n < TESTSIZE; n++) {
  85.  
  86.         delete strings[n];
  87.     }
  88.  
  89.     // And finally delete the array itself
  90.  
  91.     delete[] strings;
  92.  
  93.     _getch();
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement