Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string>
- #include <time.h>
- #include <iostream>
- #include "conio.h"
- using namespace std;
- #define TESTSIZE 10
- void FillWithTestData(int nth, char * buffer) {
- const char * data;
- switch (nth % 10) {
- case 0:
- data = "pink panties";
- break;
- case 1:
- data = "blue panties";
- break;
- case 2:
- data = "yellow panties";
- break;
- case 3:
- data = "red panties";
- break;
- case 4:
- data = "black panties";
- break;
- case 5:
- data = "teal panties";
- break;
- case 6:
- data = "gray panties";
- break;
- case 7:
- data = "white panties";
- break;
- case 8:
- data = "magenta panties";
- break;
- case 9:
- data = "invisible panties";
- break;
- default:
- data = "striped panties";
- break;
- }
- strcpy(buffer, data);
- }
- void main() {
- // Allocate the *array* to store our strings in
- char ** strings = new char*[TESTSIZE];
- for (int n = 0; n < TESTSIZE; n++) {
- // Allocate 255 bytes for a string
- strings[n] = new char[255];
- }
- // At this point I now have an array of TESTSIZE that contain a pointer to an array of 255 chars each
- for (int n = 0; n < TESTSIZE; n++) {
- // Fill out some test data
- FillWithTestData(n, strings[n]);
- }
- // And now I have TESTSIZE strings that contain test data
- // So I'll print it out:
- for (int n = 0; n < TESTSIZE; n++) {
- cout << n << ": " << strings[n] << endl;
- }
- // Now I wanna deallocate said data you'll need to deallocate everything you created with new
- for (int n = 0; n < TESTSIZE; n++) {
- delete strings[n];
- }
- // And finally delete the array itself
- delete[] strings;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement