Afficher un message
Vieux 05/05/2008, 08h45   #1
apaticul@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut An interesting c program for beginners

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
  Réponse avec citation
 
Page generated in 0,06543 seconds with 9 queries