例子
./pet
然后这是我的代码 想问下在 //1 和 //2 的地方怎么修改printf:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_NAME_LENGTH 50
#define MAX_TYPE_LENGTH 50
struct pet
{
char name[MAX_NAME_LENGTH];
char type[MAX_TYPE_LENGTH];
int age;
int weight;
};
void setup_pet(
struct pet *my_pet,
char *name,
char *type,
char *age,
char *weight);
void print_pet(struct pet *my_pet);
int main(int argc, char *argv[])
{
if (argc < 5)
{
printf("%s should receive four extra command line arguments.\n", argv[0]);
return 1;
}
struct pet new_pet;
setup_pet(&new_pet, argv[1], argv[2], argv[3], argv[4]);
return 0;
}
void setup_pet(
struct pet *my_pet,
char *name,
char *type,
char *age,
char *weight)
{
// 1
strcpy(my_pet->name, name);
strcpy(my_pet->type, type);
my_pet->age = atoi(age);
my_pet->weight = atoi(weight);
print_pet(my_pet);
}
void print_pet(struct pet *my_pet)
{
// 2
printf("%s is a %s who is %d years old and weighs %dkg\n", my_pet->name, my_pet->type, my_pet->age, my_pet->weight);
}