For a big project for school I have to make an airline reservation simulator but I have run into a problem. I want to save the the flight code and its location in a binary file so that I can obtain a code according to the location but this happens:
imgur.com/a/xhrCB (link to current output and expected output)
c-strings are null terminated, you need to reserve enough space to include the '\0' character.
(by the way, `gets()' is dangerous for this reason, don't use it)
1 2 3 4
char code[8];
int A=strlen(code);
if(A==6)
strcat(code," ");
you are too short.
However, I don't see the need to fill with spaces ¿what are you doing that for?
> imgur.com/a/xhrCB (link to current output and expected output)
use text to show text next time.
Please note that in general, it's a good idea to keep the representation of data (the way you store it) independent from the presentation of the data (the way you display it). Otherwise it's too easy to get boxed in if the requirements change.
For example, what if someone decides that they also want your data displayed in a table with different field widths, so you need a way to put it into both tables. Now the padding that you've added to the representation for the first table gets in the way of displaying it in the second table.
For a school project it probably won't make a difference, but in the real world it does.