# Thread: Just for fun: "Expecting" function

1. ## Just for fun: "Expecting" function

Hello, coding aficionados! I've dabbled a bit in C during my academics and want to have some fun with writing a short function that sums up pregnancy. I'd then like to take that code snippet and slap it on a t-shirt. I'm not that great with C so that's why I'm here!

General concept
• Have a delay function signifying 39 weeks or end date
• IF ELSE statement for girl/boy/unknown which leads to (especially fun if multiples)
• Names if they are picked out then
• Having them in the return line

I'm thinking it doesn't need to be more than 10 lines, but I'm certainly open to interpretations. I will happily credit the user that knocks my socks off.

2. As you say, this is for fun, so you don't have to take it so seriously, hence you just need to make it recognisably C. For example:
Code:
```struct baby *expecting(void) {
delay(23587200);
size_t n = 1 + random(MAX_CHILDREN);
struct baby *babies = malloc(n * sizeof(*babies));
for (size_t i = 0; i < n; i++) {
switch (random(3)) {
case 0:
babies[i].sex = GIRL;
strcpy(babies[i].name, GIRL_NAMES[random(GIRL_NAMES_COUNT)]);
break;
case 1:
babies[i].sex = BOY;
strcpy(babies[i].name, BOY_NAMES[random(BOY_NAMES_COUNT)]);
break;
}
}
return babies;
}```
The use of void as the parameter list, the use of struct baby rather than just baby, along with the malloc call, all these signal to a reader who knows C that this is likely to be a C (rather than say, C++) function, despite neither delay nor random being part of standard C. Sure, in real code we should check the return value of malloc and be wary about whether this use of strcpy might allow for buffer overflow vulnerability at some point, but that will just clutter the code snippet.

I would just omit the name thing because it doesn't add any value to this unless you have a small set of names in mind so that you can declare the names for flavour. But then you may run into the minefield of diversity in name selection. The sex vs gender thing is another minefield: I picked "sex" because it is shorter and omitted "unknown" because this is just an example, but you're going to have to navigate the sex vs gender minefield yourself, e.g., what is an "unknown" sex? Is it intersex? What is an "unknown" gender? Are the genders of all babies unknown, or are they always provisionally known due to the interpretation of people around them, etc? Consequently, you may find it easier for T-shirt purposes to omit this and say, just loop to pick random names from a pre-defined list that is not shown or something.

3. Originally Posted by laserlight
I would just omit the name thing because it doesn't add any value to this unless you have a small set of names in mind so that you can declare the names for flavour. But then you may run into the minefield of diversity in name selection. The sex vs gender thing is another minefield: I picked "sex" because it is shorter and omitted "unknown" because this is just an example, but you're going to have to navigate the sex vs gender minefield yourself, e.g., what is an "unknown" sex? Is it intersex? What is an "unknown" gender? Are the genders of all babies unknown, or are they always provisionally known due to the interpretation of people around them, etc? Consequently, you may find it easier for T-shirt purposes to omit this and say, just loop to pick random names from a pre-defined list that is not shown or something.
Thanks for the help! As you mentioned, it's not formal C so being able to recognize the basic format was the idea. I know some couples like to be surprised with the gender reveal which was the "unknown" factor, but that' doesn't really work here. Regarding the names, an arbitrary list pretty well represents it. My partner and I compiled four to five boy and girl names (from much larger lists) to pick from before finding out the gender. Well done, laserlight!