On May 5, 2:26=A0am, "Malcolm McLean" <regniz...@[EMAIL PROTECTED]
> wrote:
> <apati...@[EMAIL PROTECTED]
> wrote in message
> > void main () {
> > =A0char first[100];
> > =A0char last[100];
> > =A0int age;
> > =A0int ssn;
> > =A0float salary;
>
> > =A0readPerson(first, last, &age, &ssn, &salary);
> > =A0writePerson(first, last, age, ssn, salary);
> > }
>
> > So, my question is, how would I combine all these codes in order to
> > get a proper working program?
> > TIA
>
> Comment out everything and add printf("hello world\n") to the body of
> main(). That tells you your compiler is set up correctly.
>
> Once hello world works, comment in the smaller function, and pass it
dummy=
> data. See if it prints the dummy data. Fiddle with it until correct.
> Then turn your attention to the larger ****ntion. Try just reading in one
> variable at first. Add variables and continue fiddling with it until it
> works.
> Eventually you end up with a working program.
>
> --
> Free games and programming
goodies.http://www.personal.leeds.ac.uk/~bgy1mm=
- Hide quoted text -
>
> - Show quoted text -
Good advice, really, thanks Malcolm!
so far I could come up with a workable code,
I will have to improvise more, obviously
I'll have to figure out a way to use that "for loop" in the case of
"salary" variable. I'm just using an example from 1 to 5 to ilustrate
a
possible shortcut to get to the issue.
#include <stdio.h>
#include <ctype.h>
void readPerson (char *first, char *last,
int *age, int *ssn, float *salary) {
printf("First name: ");
gets(first);
printf("Last Name: ");
gets(last);
printf("Age: ");
scanf("%d", age);
printf("Social security number (no hyphens, just 3 figures): ");
scanf("%d", ssn);
printf("Salary: ");
scanf("%f", salary);
}
/* This writes out information about a person. */
void writePerson (char *first, char *last,
int age, int ssn, float salary) {
printf("%s %s, %d years old, SSN %d, salary of $%9.2f\n",
first, last, age, ssn, salary);
}
int main(void)
{
int i;
FILE *fp, *fs;
fs =3D fopen("ak4.bin", "wb");
for (i =3D 0; i < 5; i++) {
fputc(i, fs);
}
fclose(fs);
fs =3D fopen("ak4.bin", "rb");
fp =3D fopen("ak5.txt", "w");
while ((i =3D fgetc(fs)) !=3D EOF) {
printf("%d\n", i);
fprintf(fp, "%c", isprint(i) ? i : '.');
fprintf(fp, " %d\n", i);
}
{
char first[100];
char last[100];
int age;
int ssn;
float salary;
readPerson(first, last, &age, &ssn, &salary);
writePerson(first, last, age, ssn, salary);
}
}


|