C Program : let us look at the output for the program shared recently

in c-programming •  last year 

Welcome back,
In today's blog i am going to discuss the outpur for the program shared recently. If you don't want to see the output then leave this blog here and visit the blog shared yesterday.

Try to find the output of the program and in case you face difficulty visit here and see the program output.

Let us look at the program itslelf,

Screenshot 2023-07-13 210114.png

Screenshot 2023-07-13 210127.png

Screenshot 2023-07-13 210138.png

Screenshot 2023-07-13 210151.png

#include <stdio.h>
#include <string.h>

#define MAX_ANIMALS 100
#define MAX_NAME_LENGTH 100
#define MAX_OWNER_LENGTH 100

typedef struct {
char name[MAX_NAME_LENGTH];
char owner[MAX_OWNER_LENGTH];
} Animal;

int main() {
Animal animals[MAX_ANIMALS];
int numAnimals = 0;

// Input animals and their owners
printf("Enter the details of the animals:\n");
printf("Enter 'exit' to stop.\n");

while (1) {
char name[MAX_NAME_LENGTH];
char owner[MAX_OWNER_LENGTH];

printf("Enter animal name: ");
fgets(name, MAX_NAME_LENGTH, stdin);
name[strcspn(name, "\n")] = '\0'; // Remove the trailing newline

// Check if the user wants to exit
if (strcmp(name, "exit") == 0) {
break;
}

printf("Enter owner name: ");
fgets(owner, MAX_OWNER_LENGTH, stdin);
owner[strcspn(owner, "\n")] = '\0'; // Remove the trailing newline

// Store the animal and owner details
if (numAnimals < MAX_ANIMALS) {
strcpy(animals[numAnimals].name, name);
strcpy(animals[numAnimals].owner, owner);
numAnimals++;
printf("Animal details added.\n");
} else {
printf("Maximum number of animals reached.\n");
break;
}
}

// Search for an animal
printf("\nEnter the name of an animal to search: ");
char searchName[MAX_NAME_LENGTH];
fgets(searchName, MAX_NAME_LENGTH, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // Remove the trailing newline

// Iterate over the animals to find a match
int found = 0;
for (int i = 0; i < numAnimals; i++) {
if (strcmp(searchName, animals[i].name) == 0) {
printf("Owner of %s: %s\n", animals[i].name, animals[i].owner);
found = 1;
break;
}
}

if (!found) {
printf("Animal not found.\n");
}

return 0;
}

I am not going to share the explanation in this blog and i will be doing that tomorrow. SO let us directly look at the output of this program.

image.png

So that is how the output shall look like for the program we shared yesterday.

If you also want to learn basics and start your C programming journey then find a teacher today for free on Youtube.

I learnt alot from a teacher who teaches c in hindi and if you are finding someone who teaches in hindi then this person will definitely help you.

Source

I am happy to call myself a trader and small programmer at the same time now.

Happy trading and keep learning what you love.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!