Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: An interest...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 26065 of 26959
Post > Topic >>

Re: An interesting c program for beginners

by apaticul@[EMAIL PROTECTED] May 5, 2008 at 04:23 AM

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);



}


}
 




 8 Posts in Topic:
An interesting c program for beginners
apaticul@[EMAIL PROTECTED  2008-05-04 23:45:50 
Re: An interesting c program for beginners
Richard Heathfield <rj  2008-05-05 07:48:07 
Re: An interesting c program for beginners
"Malcolm McLean"  2008-05-05 09:26:35 
Re: An interesting c program for beginners
apaticul@[EMAIL PROTECTED  2008-05-05 04:23:26 
Re: An interesting c program for beginners
Niz <niz@[EMAIL PROTEC  2008-05-05 13:18:22 
Re: An interesting c program for beginners
"Bill Leary" &l  2008-05-05 10:25:32 
Re: An interesting c program for beginners
William Pursell <bill.  2008-05-05 13:15:45 
Re: An interesting c program for beginners
Nick Keighley <nick_ke  2008-05-06 03:58:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:13:28 CDT 2008.