NO

Author Topic: Need help  (Read 2632 times)

Jitesh

  • Guest
Need help
« on: October 18, 2004, 01:09:09 PM »
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);

}

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Need help
« Reply #1 on: October 18, 2004, 03:34:30 PM »
I changed it a bit. Maybe this will help.

Code: [Select]

#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