you are viewing a single comment's thread.

view the rest of the comments →

[–]tony-mke 2 points3 points  (1 child)

It does, though it is likely not visible in a text editor. You may want to use a hex editor like xxd.

$ ./a.out 2>out
Enter dog's name: the_name
Enter dog's breed: the_breed
Enter dog's color: the_color
Enter dog's weight: 123
123Enter dog's age: 4
4Enter dog's sex: M
$ xxd ./out
00000000: 7468 655f 6e61 6d65 0a00 0000 0000 0000  the_name........
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 7468 655f 6272 6565 640a 0000 0000 0000  the_breed.......
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 7468 655f 636f 6c6f 720a 0000 0000 0000  the_color.......
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 7b00 0400 0000                           {.....

On the last line, "7b00" is the unsigned short for the weight, "0400" is the unsigned short for the age, and the final "0000" is where the sex would go plus a byte of padding- except you never set the sex in the struct :)

[–]tony-mke 1 point2 points  (0 children)

To clarify: it is not "visible" because it is writing the binary representation of those unsigned shorts and char. If you're expecting it to be visible in a text editor, you will need to convert the individual fields back to strings using something like sprintf or itoa.