Ваша проблема в том, что get ведет себя не так, как вы этого хотите. Вы не должны использовать get в любом случае, потому что это опасно и может вызвать переполнение . Но, к счастью, scanf может легко читать строки, а также позволяет указывать формат (в этом случае% 24s, потому что вы хотите прочитать до 24 символов, потому что последний символ зарезервирован для нулевого терминатора.
Код работает так:
#include <stdio.h>
struct dogInfo
{
char type[25];
char colour[25];
int legNum;
float snoutLen;
};
int main()
{
struct dogInfo dog[3]; //Array of three structure variable
int ctr;
//Get information about dog from the user
printf("You will be asked to describe 3 dogs\n");
for (ctr = 0; ctr < 3; ctr ++)
{
printf("What type (breed) of dog would you like to describe for dog #%d?\n", (ctr +1));
scanf("%24s", dog[ctr].type);
puts("What colour is the dog? ");
scanf("%24s", dog[ctr].colour);
puts("How many legs does the dog have? ");
scanf(" %d", &dog[ctr].legNum);
puts("How long is the snout of the dog in centimetres? ");
scanf(" %.2f", &dog[ctr].snoutLen);
getchar(); //clears last new line for the next loop
}
}