I don't know jack about Visual Studio, and I'd like to keep it that way because I like doing stuff on the command line, I have my preferences. But my teacher uses it to compile and I'm curious what I did wrong because gcc didn't throw anything.

So, code (Without header, which just defines constants and function names):

#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include "midterm.h"
void draw();
BITMAP *sc;
SAMPLE *clap, *bounce;
int color;


void start()
{
    score=0;
    b.sp = speed;
    b.rad = radius;
    p.x = width/2;
    p.y = height-margin;
    p.length = paddle_length;
    num_lives=3;
    num_blocks = 30;
    top=0;
    go=0;
    internal_ptr=0;
    setblocks();
    b.x=width/2;
    b.y=(height/2)+radius+5;
    b.dy=speed;
    b.dx=0;
}

void setblocks()
{
    int ww = width-(margin*2);
    int hh = height-(margin*2);
    int numrows=0;
    int numcols=0;
    int rowspace,colspace;
    if(isdiv(num_blocks,5))
    {
        numrows = 5;
        numcols = num_blocks/5;
    }
    else if(isdiv(num_blocks,6))
    {
        numrows = 6;
        numcols = num_blocks/6;
    }
    else if(isdiv(num_blocks,7))
    {
        numrows = 7;
        numcols = num_blocks/7;
    }
    else if(isdiv(num_blocks,8))
    {
        numrows = 8;
        numcols = num_blocks/8;
    }
    else if(isdiv(num_blocks,9))
    {
        numrows = 9;
        numcols = num_blocks/9;
    }
    //top = new struct block;
    wall_depth=(hh/4);
    block_length = (9*ww)/(10*numcols);
    colspace = ww/(10*(numcols+1));
    block_height = (9*wall_depth)/(10*numrows);
    rowspace = wall_depth/(10*(numrows+1));
    int starty=margin+rowspace;
    int i;
    for(i=0;i<numrows;i++)
    {
        int startx=margin+colspace;
        int j;
        for(j=0;j<numcols;j++)
        {

            add(&top,startx,starty);
            startx+=block_length+colspace;
        }
        starty += block_height+rowspace;
    }
}

int isdiv(int a, int c)
{
    return !(a%c);
}

void paint_ball(int *x,int *y)
{
    *x = b.x;
    *y = b.y;
}

void paint_paddle(int *lx,int *ly, int *rx, int *ry)
{
    *lx = p.x-(p.length/2); *ly=p.y; *rx = p.x+(p.length/2); *ry=p.y+5;
}

int paint_blocks(int *lx,int *ly, int *rx, int *ry)
{
    int good=(internal_ptr<num_blocks);
    if(good)
    {
        struct block *a = top;
        int i;
        for(i=0;(i<internal_ptr&&(a!=0));i++)
        {
            a=a->next;
        }
        if(a!=0)
        {
            *lx = a->x; *ly = a->y; *rx = *lx + block_length; *ry=*ly + block_height;
            internal_ptr++;
        }
        else
        {
            internal_ptr=i;
        }
    }
    else
    {
        internal_ptr=0;
    }
    return good;
}

int getscore()
{
    return score;
}
int gameover()
{
    return (!num_lives)||(!num_blocks);
}

void move()
{
    if(go)
    {
        b.x+=b.dx;
        b.y+=b.dy;
        checkbounce();
    }
}
void checkbounce()
{
    if((b.x-b.rad)<margin)
    {
        b.dx=-b.dx;
        b.x=margin+b.rad+5;
    }
    else if((b.x+b.rad)>(width-margin))
    {
        b.dx=-b.dx;
        b.x=width-margin-b.rad-5;
    }
    else if((b.y-b.rad)<margin)
    {
        b.dy=-b.dy;
        b.y=margin+b.rad+5;
    }
    else if((b.y+b.rad)>height+2)
    {
        num_lives--;
        startcond();
    }
    else
    {
        checkbrickhit(&top);
        checkpaddlehit();
    }
}

void checkbrickhit(struct block **a)
{
    struct block *nnew=0;
    int xx,yy;
    int q=0;
    int i;
    for(i=0;i<num_blocks;i++)
    {
        xx=(*a)->x;
        yy=(*a)->y;
        if(!((b.x>=xx)&&(b.x<=(xx+block_length))&&(abs(b.y-yy)<(b.rad+block_height))))
        {
            struct block *c = malloc(sizeof(struct block));
            deepcopy((*a),&c);
            c->next=0;
            push(&nnew,c);
        }
        else
        {
            q++;
            score++;
        }
        pop(a);
    }
    num_blocks-=q;
    *a = nnew;
}

void startcond()
{
    go=0;
    b.x=width/2;
    b.y=(height/2)+b.rad+5;
    b.dy=b.sp;
    b.dx=0;
}

void startstop()
{
    go=(go+1)%2;
}  

void movepaddle(int i)
{
    int inc = (width/(p.length+10));
    if(i)
    {
        if((p.x-(p.length/2))>=margin)
        {
            p.x-=inc;
        }
    }
    else
    {
        if((p.x+(p.length/2))<=(width-margin))
        {
            p.x+=inc;
        }
    }
}

void checkpaddlehit()
{
    int xx=p.x;
    int yy=p.y;
    int checkx = b.x>=(xx-(p.length/2))&&b.x<=(xx+(p.length/2));
    int checky = ((b.y-yy)>-(b.rad) && (b.y-yy)<(b.rad*2));
    if(checkx&&checky)
    {
        b.y = p.y-b.rad-2;
        int px = b.x-p.x;
        b.dx=(2*b.sp*px)/p.length;
        b.dy=-b.dy;
    }
}

    //linked list stuff
void push(struct block **a, struct block *c)
{
    c->next=*a;
    *a = c;
}

void add(struct block **a, int x, int y)
{
    if(*a!=0)
    {
        struct block* nnew = malloc(sizeof(struct block));
        nnew->x=x;
        nnew->y=y;
        nnew->next = *a;
        *a = nnew;
    }
    else 
    {
        *a = malloc(sizeof(struct block));
        if(*a==0)
        {
            printf("In add, malloc operator failed!!!!!!!!!!!!!!!!!!!!!!!!\n");
        }
        (*a)->x=x;
        (*a)->y=y;
        (*a)->next=0;
    }
}

void deepcopy(struct block *a, struct block **c)
{
    (*c)->x=a->x;
    (*c)->y=a->y;
}

void pop(struct block **a)
{
    struct block *c = *a;
    *a=c->next;
    free(c);
}

void destroygame()
{
    int i;
    for(i=num_blocks;i>0;i--)
    {
        struct block *a = top;
        int j;
        for(j=0;j<i;j++)
        {
            a=a->next;
        }
        a->next=0;
        free(a);
    }
} 
void draw()
{
    move();

    clear_to_color(sc,color);
    rect(sc,margin,margin,width-margin,height-margin,0);
    int cc = makecol(255,255,0);


    textprintf_ex(sc, font, width/2-30, 1, 15, -1,
        "Score: %i",getscore());

    textprintf_ex(sc, font, 5, 5, 15, -1,"Lives: %i",num_lives);

    int lx,ly,rx,ry;

    paint_ball(&lx,&ly);
    circlefill(sc,lx,ly,radius,cc);

    paint_paddle(&lx,&ly,&rx,&ry);
    rectfill(sc,lx,ly,rx,ry,cc);

    while(paint_blocks(&lx,&ly,&rx,&ry))
    {
    rectfill(sc,lx,ly,rx,ry,makecol(255,0,0));
    }

    blit(sc,screen,0,0,0,0,width,height);

}
int main(int argc, char *argv[])
{
    start();
    //initialize Allegro
    allegro_init(); 
    install_keyboard(); 
    install_timer();

    //initialize video mode to 640x480
    int ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0);
    if (ret != 0) {
        allegro_message(allegro_error);
        return 1;
    }

    color = makecol(50,50,150);

    //initialize the screen cover
    sc = create_bitmap(SCREEN_W,SCREEN_H);
    clear_to_color(sc,color);

    int delay_factor=10;
    //int count=0;

    int quit=0;
    while(!quit&&!gameover())
    {
    rest(20);
    draw();
    rest(20);
    if(keypressed())
    {
        if(key[KEY_LEFT])
        {
            movepaddle(1);
        }
        else if(key[KEY_RIGHT])
        {

            movepaddle(0);
        }
        else if(key[KEY_ENTER])
        {
            startstop();
        }
        else if(key[KEY_ESC])
        {
            quit++;
        }
    }
    //count = (count+1)%delay_factor;
    }
    if(!quit)
    {
        textprintf_ex(screen, font, (width/2)-5, height/2, 15, -1, "GAME OVER");
        char *c;
        if (getscore()==30)
        {
             textprintf_ex(screen, font, (width/2)-5, (height/2)-30, 15, -1,"YOU WIN!");
        }
        else
        {
              textprintf_ex(screen, font, (width/2)-5, (height/2)-30, 15, -1,"YOU LOSE!");
        }
        while(!key[KEY_ESC]&&gameover())
        {
        }
    }
    destroygame();
    destroy_bitmap(sc);
    allegro_exit();
}
END_OF_MAIN();

Sorry for the long code its supposed to be similar to the game breakout and plus I originally wrote it in C++ but due to a misunderstanding I thought I had to translate it into C (irrelevant btw just adding some info)

I figured it might be because the compiler for MSVC8 is more strict, so I tried -Wall and -pedantic, wall just dinged me on unused variables and something else, pedantic said something about C90 forbinds mixed declarations and code. And something about conversion of function pointer to object. whatever.

My teacher got:

Error      11           error C2440: 'initializing' : cannot convert from 'void *' to 'block *'    main.cpp       188        

Error      12           error C2440: 'initializing' : cannot convert from 'void *' to 'block *'    main.cpp       263        

Error      13           error C2440: '=' : cannot convert from 'void *' to 'block *' main.cpp   271

It's OK to be somewhat stubborn, but when you're wrong, is not the time. Of course, they're built to different standards, they're years apart, and from different lineages, as well.

Don't be that silly student who uses a different compiler than his teacher, because he "has preferences". ?? This is not speed dating!

Get with the program.

The error(s) reported by vc++ is because the compiler is compiling the source files as c++ instead of C. In C the return value of void* functions such as malloc() do not need to be typecast, but in c++ they do. This is a requirement of the C and C++ ISO standards. Your source file has *.cpp extension as indicated in the error message, so it's being compiled as c++. Change the extension to *.c and the erorr(s) will go away.

I suspect gcc does not complain because you named the source files with *.c extension instead of *.cpp

In VC++ 2008 after creating the c++ project you have rename the files with *.c extension.

It's OK to be somewhat stubborn, but when you're wrong, is not the time. Of course, they're built to different standards, they're years apart, and from different lineages, as well.

Don't be that silly student who uses a different compiler than his teacher, because he "has preferences". ?? This is not speed dating!

Get with the program.

Fair enough. But in my defense, I couldn't get the damn environment set up correctly. I run windows on mac and apparently I either am missing libraries or they aren't in the right spot. I don't remember it was a while ago. I'll create another thread and ask for help. Your right though.

Also, Thank you Ancient Dragon thats what I was looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.