"Console Program Output" problem

Started by manolojohny, January 09, 2012, 05:33:16 PM

Previous topic - Next topic

manolojohny

//exercise 1
#include<stdio.h>
struct cars
{
        char manufacturer[20],model[20];
        int engine_cc,year,cost;
}x[1];
void printcars();
int main()
{
int i;
for (i=0; i<=1; i++)
{
        printf("Insert cc of the engine,year of manufacture,cost,the manufacturer and the model of the car...\n");
        scanf("%d%d%d",&x.engine_cc,&x.year,&x.cost);
        fflush(stdin);
        scanf("%s",&x.manufacturer);
        fflush(stdin);
        scanf("%s",&x.model);
        fflush(stdin);
        printf("next car:\n");
}
printcars(x);
}

void printcars()
{
int i;
for (i=0; i<=1; i++)
{
        printf("Car[%d]:\nmanufacturer:%c\nmodel:%c\nengine:%d\nyear:%d\ncost:%d\n\n",i,x.manufacturer,x.model,x.engine_cc,x.year,x.cost);

}
}

For some reason I don't know when I execute this,the "console program output" window stops working after I insert the model of the second time!
there is also a message that says "exercise 1.exe has stopped working"

could you please tell me what's going on?

czerny

You havn't done this with Pelles C? Right?

czerny

Bitbeisser

Quote from: manolojohny on January 09, 2012, 05:33:16 PMFor some reason I don't know when I execute this,the "console program output" window stops working after I insert the model of the second time!
there is also a message that says "exercise 1.exe has stopped working"

could you please tell me what's going on?
Well, beside that the program as you posted it doesn't compile in Pelle's C, which probably is the reason why czerny posted his reply, the program rather seems to do exactly what you programmed to do.

Both the input and the output (printcars() ) run for exactly 2 loops...

Ralf

CommonTater

There are too many problems with the program itself to tell if there is any reportable bug in Pelles C, here.

You need to sort out your own code before you make bug reports...

Bitbeisser

Quote from: CommonTater on January 09, 2012, 11:37:15 PM
There are too many problems with the program itself to tell if there is any reportable bug in Pelles C, here.

You need to sort out your own code before you make bug reports...
Oops, didn't even realize that this was posted in the "Bug reports" section. A moderator should move this thread into the beginners section instead... ???

Ralf