Advertisement

how to return value from a function and exit it after that

Started by May 06, 2020 09:56 PM
3 comments, last by cozzie 4 years, 8 months ago

I write a program to learn english with sdl2 and I want to return a vlue from a function in another function every function have separate window and I want to close window after return this value how ?

I can't do it it's very dificult please help.

this is the code of my function:

int Lrecord::select_mic(SDL_Event* le)

{

int index = 100;

mWindow = SDL_CreateWindow("select mic", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN);

if (mWindow == NULL)

printf("window error... %s", SDL_GetError());

SDL_Renderer *srender = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);

if (srender == NULL)

printf("renderer error %s", SDL_GetError());

mWindowID = SDL_GetWindowID(mWindow);

tex1.loadmedia(srender);

tex1.loadtext("Select your mic from the list by press its number: ", mTextColor, srender);

tex1.render(srender, 0);

//Get capture device count

tex1.gRecordingDeviceCount = SDL_GetNumAudioDevices(SDL_TRUE);

//No recording devices

if (tex1.gRecordingDeviceCount < 1)

{

printf("Unable to get audio capture device! SDL Error: %s\n", SDL_GetError());

}

//At least one device connected

else

{

//Cap recording device count

if (tex1.gRecordingDeviceCount > MAX_RECORDING_DEVICES)

{

tex1.gRecordingDeviceCount = MAX_RECORDING_DEVICES;

}

//Render device names

std::stringstream promptText;

for (int i = 0; i < tex1.gRecordingDeviceCount; ++i)

{

//Get capture device name

promptText.str("");

promptText << i << ": " << SDL_GetAudioDeviceName(i, SDL_TRUE);

//Set texture from name

tex1.loadtext(promptText.str().c_str(), mTextColor, srender);

tex1.render(srender, i + 1);

}

}

if (le->type == SDL_KEYDOWN)

{

//Handle key press from 0 to 9

if (le->key.keysym.sym >= SDLK_0 && le->key.keysym.sym <= SDLK_9)

{

//Get selection index

index = le->key.keysym.sym - SDLK_0;

}

}

return index;

}

None

and I want to return index value to another function in it

None

Advertisement

@tkialwan Can you edit your first post and put the code in code tags so it is spaced and tabbed properly?

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

I don’t think what you’re asking is possible (literally). It’s also hard for the function calling code to now when it’s done, because return means proceed with the next line of code. You could rewrite your function and maybe add a reference function Parameter to “return” that value

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement