使用SDL C时在终端上打印

时间:2017-05-01 01:57:52

标签: c terminal sdl

我在SDL中编写一个程序,唯一的问题是我希望用户从终端输入一些输入,但是当我执行printf时,什么都没有出现。 我找到了这个thread

他们在这里说:

I believe SDL redirects all output intended for stdout/stderr to files stdout.txt/stderr.txt. Check the folder your program runs in for those files.

但是我启动该程序的文件夹中没有任何内容。 任何人都知道如何找到这个文件(如果它们对我需要做的有用,或者使用SDL库用C在终端中打印输出的方法?

这是代码:

#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//line algorithm http://www.dreamincode.net/forums/topic/246895-draw-lines-in-c-with-sdl/


char *inputString(FILE* fp, size_t size){
//The size is extended by the input with the value of the provisional
    char *str;
    int ch;
    size_t len = 0;
    str = realloc(NULL, sizeof(char)*size);//size is start size
    if(!str)return str;
    while(EOF!=(ch=fgetc(fp)) && ch != '\n'){
        str[len++]=ch;
        if(len==size){
            str = realloc(str, sizeof(char)*(size+=16));
            if(!str)return str;
        }
    }
    str[len++]='\0';

    return realloc(str, sizeof(char)*len);
}


int main(int argc, char** argv)
{
    char *imagePath;
    while(1)
    {
        printf("Input Image Path(just image if in exectuable folder):\n");
        imagePath = inputString(stdin, 10);
        printf("%s\n", imagePath);
    }
    printf("ciao\n");
    free(imagePath);
    static const int winWidth = 640;
    static const int winHeight = 480;
    int go;
    SDL_Event event;

    //creating the window
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = NULL;
    SDL_Surface *canvas = NULL;
    SDL_Renderer *renderer = NULL;

    window = SDL_CreateWindow("Drawing Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winWidth, winHeight, SDL_WINDOW_SHOWN);

    canvas = SDL_GetWindowSurface(window);

    SDL_FillRect(canvas, NULL, SDL_MapRGB(canvas->format, 255, 255, 170));

    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

    go = 0;
    while( go==0 )
    {


        SDL_RenderClear(renderer);

        SDL_WaitEvent(&event);
        switch( event.type )
        {
        case SDL_QUIT:
            go = 1;
            break;

        }

        SDL_UpdateWindowSurface(window);
        SDL_RenderPresent(renderer);

    }

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

0 个答案:

没有答案