So my first question is, how do I do a file input/output program on a Mac using Xcode and terminal?
Second, until I figure that out, would someone mind telling me if this is correct since I am unable to compile and run it currently? I am going to partition my drive this week and throw windows on it but until then I would like to study for my exam.
Here's the Practice problem: Write a program that reads in from the first line an integer n, and thereafter on n subsequent lines two things per line (an int SSN and a float wages-earned). All this is form a file. You must prompt for the filename as a string that is certain to be less than 30 chars long. Open the file, etc., read everything, and keep a running total of all the wages earned, then when reading is complete, prompt for an output filename string, open it and write to it the average value of all the earnings.
Here's my code:
#include <stdlib.h>
#include <stdio.h>
FILE *F1, *F2;
void main () {
int SSN, n, i;
float wages, total;
char f1name, f2name;
scanf("%s", &f1name);
F1 = fopen("f1name", "r");
fscanf(F1,"%d", &n);
{
// Reading in the
for(i=0; i<n; i++)
{
fscanf(F1,"%d%f", &SSN, &wages);
total += wages;
}
// Scanning in file name and opening it
scanf("%s", &f2name);
F2 = fopen(fname, "w");
// Writing to the file the average of all earnings
fprintf(F2,"%d%f", SSN, total/n);
}
// Closing the file
fclose(F1);
fclose(F2);
}