Guys, I really, REALLY need your help getting info into a structure. (Please help!)
I had this posted at the C++ board, but than I realized this is a C problem!
Ok first I have a notpad called "family.in" saved to my a drive with 5 family members info that looks just like this:
Joe Redfield
6220 Culebra
San Antonio, TX 78228
Self
10-03-56
45
(plus 4 other people)
Now I have to make a program that gets this info. Prints it to a screen and than makes an out file called "family.out" with the info turning into this (gotta show it as code, so the spaces will show):
Code:
Joe Redfield Relation: Self
6220 Culebra Birthday: 10-03-56
San Antonio, TX 78228 Age: 45
I do have a program running, so Im not asking anyone to do the work for me. I just need help getting the info and making it print out like the way its suppose to above. Instead, it prints out to the screen like the way it looks in the "family.in" file. But in the "family.out" file it looks like this:
Joe Redfield
6220 Culebra
San Antonio, TX 78228
Self
10-03-56
45
I have no idea how to grap individual bits of info and I have no idea how Im suppose to get it to look the way my damn teacher wants it. My code is below, and I really hope theres someone here who can help me out. Thank you very much and its very appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct family {
char name [50]; /* person's name */
char street [50]; /* street address */
char csz [50]; /* city, state, zip */
char relation [50]; /* relation to you */
char birthday [50]; /* mm-dd-yy */
char age [50]; /*person's age */
};
struct family PEOPLE[5], *member;
void main (void)
{
char linein[50];
char getdata[50];
int index;
FILE *in, *out;
index = 0;
in = fopen ("a:\\family.in", "r");
out = fopen ("a:\\family.out", "w");
while ( !feof(in) )
{
fgets(linein, 50, in);
getdata[index]=linein[50];
printf("%s", linein);
index++;
fprintf(out, " %s \n", linein);
}
printf("\n\nThe value is: %s\n\n", getdata[1]);
fclose(in);
fclose(out);
}