How will a C program help you in real life

in hive-175254 •  2 years ago 

Today we will see how you can use c programming to help yourself in a real life situation. Suppose we are running a organization where we have to keep the record of people name, age, and, occupation.

How to write a c program to solve this problem. You will find that in this blog.

Screenshot 2023-01-03 214633.png

Copy the code below :

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

int main() {
char name[100];
int age;
char occupation[100];

printf("Enter your name: ");
fgets(name, sizeof(name), stdin);
name[strlen(name)-1] = '\0';

printf("Enter your age: ");
scanf("%d", &age);

printf("Enter your occupation: ");
fgets(occupation, sizeof(occupation), stdin);
occupation[strlen(occupation)-1] = '\0';

printf("\nName: %s\n", name);
printf("Age: %d\n", age);
printf("Occupation: %s\n", occupation);

return 0;
}

To understand how this program will work like , let us run it and see a live example.

Screenshot 2023-01-03 215210.png

In this example, the user entered their name as "John Smith," their age as 35, and their occupation as "Software engineer." The program then printed out this information, along with the corresponding labels ("Name," "Age," and "Occupation").

image.png

Source

Our program has few limitations as well , They are :

  1. The program assumes that the user will always enter their name, age, and occupation in the correct format. If the user does not follow the prompts or enters invalid input, the program may produce unexpected results or even crash.

  2. The program can only handle input that is less than 100 characters in length. If the user enters a name or occupation that is longer than 100 characters, it will be truncated.

  3. The program does not validate the age input to ensure that it is a positive integer. If the user enters a negative number or a non-integer value, the program will treat it as a valid age.

If you also want to learn coding then find your teacher according to your language. For me i am comfortable with hindi language and follow hindi teachers.

You can refer to my teacher below in case you are also comfortable with hindi.

Source

I will soon call myself a trader and a small programmer together.

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 STEEM!
Sort Order:  

Hello @theindiantrader

Thank you for posting within our project.hope community on STEEMit.

Please spare few minutes and read how project.hope is organized and learn about our economy. You can find link here: https://steemit.com/hive-175254/@project.hope/project-hope-economy-explained-2021

That would help you understand more our goals and how are we trying to achieve them. Hopefully you will join our community and become strong part of it :)

Do you use telegram or discord? If you do then join our server and give me a shout. I would gladly share with you goals of our community and introduce to others from our team.

Consider joining our discord server: https://discord.gg/uWMJTaW

Yours,
@project.hope team,

sure, i am on discord and i have just joined the server.