Talk About Network



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 > An interesting ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 26065 of 26198
Post > Topic >>

An interesting c program for beginners

by apaticul@[EMAIL PROTECTED] May 4, 2008 at 11:45 PM

Hi all,

O.K.  here is an attempt to create a c program
which consists of
a structure, where you're supposed to enter some personal information.
Now, it's pretty obvious some folks would enter a larger ammount of
salary lets say a 6 figure.
My attempt is to have a few files, called result1.txt, result2.txt,
and result3.txt,  saved in the same folder as the c program, lets call
it
"personalinfo.c"

this result.txt* files, would be as such:
result1.txt: "6 figure salary? Yeah, right! Try again (and cut a few
0's ;-) )
result2.txt: "5 figure salary? Good for you!"
result3.txt: "4 figure salary? Right on!"

the following is the I/O file
that would be included with the persoalinfo.c:
{

  int x;
  FILE *infile;

  /* Always check to make sure that you succeeded in opening the file.
*/

  infile = fopen("result.txt", "r");
  if (infile == NULL)
    printf("Unable to open result.txt\n");

  else
    {
      while (fscanf(infile, "%d", &x) != EOF)
        printf("%d\n", x);

      fclose(infile);
    }

this above code is supposed to pop-up in the command prompt afterwards
you've entered your personal data.


Next, the following is the personalinfo.c (will require stuff from the
above mentioned files)


#include <stdio.h>


/* This prompts for and reads information about a person.  Everything
   is returned though the parameters, which are passed by reference.
*/

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


/* Reads in and writes out information about a person. */

void main () {
  char first[100];
  char last[100];
  int age;
  int ssn;
  float salary;

  readPerson(first, last, &age, &ssn, &salary);
  writePerson(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




 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 Tue May 13 14:54:03 CDT 2008.