
Originally Posted by
MrCricket
Thanks for quick reply.
This one question is pretty stupid but still...
Imagine I make a small struct of a client with his Name, Phone Number and age. I fill all the information of Client1
If I want to make a function just for the sake of change one of the components of Client1. How do I do that?
Consider this code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define NAME_LEN 10
typedef struct
{
char name[NAME_LEN];
uint64_t phone_num;
unsigned age;
}Person;
Person change_age(Person p, unsigned new_age)
{
p.age=new_age;
return p;
}
int main(void)
{
Person p1={.name="Bob", .phone_num=111111, .age=30};
p1 = change_age(p1,20);
printf("p1.age==%u\n",p1.age);
return EXIT_SUCCESS;
}