Problems with char and LPCSTR

closed account (2NywAqkS)
I have made a program that randomly generates a street name. it worked fine as a console application. Now that I have learn't a bit about it I thought I would try turning it into a window application. I did this but when I try to put my char's and strings into a message box I get this error.

error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'char' to 'LPCSTR'

here's the code


// Street Name - The aim of this is to generate plausable Street names
#include <iostream>
#include <windows.h>
#include "random.h"
#include <string>
#include <cstdlib>
#include <ctime>
#include <WCHAR.h>
using namespace std;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int CmdShow)
{
while(1<2)
{
char v[] = "aeiou";
char C[] = "BCDFGHJKLMNPRSTVWYZ";
char c[] = "bcdfghjklmnprstvwyz";
char p[4][7] = {"Avenue","Road","Street","Lane"};

char C1 = C[random(20)];

srand((unsigned)time(0)/2);
int r = (rand()% 21);

char c2 = c[r];

char v1 = v[random(4)];

srand((unsigned)time(0)/2);
int r2 = (rand()% 4);

char v2 = v[r2];

string p1 = p[random(3)];

int msgboxID = MessageBoxA (NULL, C1, "Random Street Name Generator", MB_RETRYCANCEL);

if (msgboxID == IDCANCEL) return 0;

}
}

also where it say ...NULL, C1,
i want to have it so it prints C1 then v1 then c2 then v2 then p1

any help is much apprieciated.
C1 is a variable of type char, but MessageBoxA() expects one of type char* (a pointer to char), and it expects that the char array pointed to by the pointer your provide has at least one element whose value is the null char (numeric value 0) that signals the end of the string.
closed account (2NywAqkS)
so what is the solution?
You need to display this:

char C1Display[] = {C1, '\0'};
closed account (2NywAqkS)
Thank you very much!
Topic archived. No new replies allowed.