So I have this project to program an "auto parts management" C program. Basically I need to be able to add and delete lines of text from a text file. Also, I need to be able to edit lines of text. Lines of text are in the format:
PART NAME : OWNER : STATUS : SYSTEM DATE : CO NAME
Although I don't know much about them, structures would seem like they would be useful. I think in my case it would look like this:
struct parts
{
char pname [PNAME_LEN+1];
char owner [OWNER_LEN+1];
char status [3]; //toggles between in/out
char date [10]; // MM/DD/YYYY format.
char oname [ONAME_LEN+1];
} part1, part2, part3; //etc... I assume I need a loop
//to increment part.
To add a part, the program will prompt the user for a pname and an owner. So once I have those two things captured in variables, I need to initialize part1 so it contains "pname:owner:in" with the date and co name left blank. Will this work?
struct parts part1;
strcpy(part1.pname, pname);
strcpy(part1.oname, owner);
strcpy(part1.status, "in");
How would I then print part1 into a text file?