News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Need help

Started by Jitesh, October 18, 2004, 01:09:09 PM

Previous topic - Next topic

Jitesh

Hi my name is jitesh and i'am new in c programing. I wrote this piece of code it's ment to  take in information from the user about a car and display it back on the screen after the code is excuted but unfourtunately i can'nt make it do that and i have tried everything and nothing worked. I will be highly greatful if you can help in in any way.

#include<stdio.h>

typedef struct{
   char make[10], model[10];
   int odometer;

}car_t;



int getCar(car_t *c);
void showCar(car_t c);


int
main(void)
{

char model;
char make;
int odometer;
printf("Who made the car\n");
scanf("The car is of type %s  made %s in and has odoometeder %d of.\n",model, make, odometer);
getCar(car_t *c);



return(0);
}


int
getCar(car_t *c)
{
   int status;

   status = scanf("%s%s%", &c->make, &c->model);

   if (status == 2)
   status = 1;
else if (status !=2)
status = 0;

status = scanf("%d", &c->odometer);
if (status == 1)
   status = 1;
else if (status !=EOF)
status = 0;

return(status);

}

void
showCar(car_t c)
{
char a, b;
int d;

a = c.make;
b = c.model;
d= c.odometer;

printf("Enter the name of the car.\n");
scanf("%s", a);

printf("Enter the model of the car.\n");
scanf("%s", b);

printf("Enter the odometer reading of the car.\n");
scanf("%d", c);

}

Pelle

I changed it a bit. Maybe this will help.


#include<stdio.h>

typedef struct {
   char make[10], model[10];
   int odometer;
} car_t;

int getCar(car_t *c);
void showCar(car_t c);

int main(void)
{
   car_t c;

   if (getCar(&c) != 0)
       return 0;

   showCar(c);

   return 0;
}

int getCar(car_t *c)
{
   printf("Enter the name of the car.\n");
   if (scanf("%s", c->make) != 1)
       return -1;

   printf("Enter the model of the car.\n");
   if (scanf("%s", c->model) != 1)
       return -1;

   printf("Enter the odometer reading of the car.\n");
   if (scanf("%d", &c->odometer) != 1)
       return -1;

   return 0;
}

void showCar(car_t c)
{
   printf("\n");
   printf("Name of the car is %s\n", c.make);
   printf("Model of the car is %s\n", c.model);
   printf("Odometer reading of the car is %d\n", c.odometer);
}


Pelle
/Pelle