Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C help

Name: D: 2008-05-07 2:35

I can't get this fucking code to read from a text file (payroll.txt) I have to include with the program. Maybe I'm a dumbass and not putting it in the right place (I put it in the root file where the code goes, but it's not working so...dunno). Anyway, pals, proofread my shitty code if you would be so kind.

/*This program prints a payroll register. It collects data from payroll.txt, an external file
that is put in the folder along with the program.*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int test;/*Used simply to stop the program from exiting*/
    FILE *payPtr;
    payPtr = fopen("payroll.txt", "r");
    int i = 1;
    int j = 1;
    double pay, fica, medicare, tax, dues, net, hoursOver;
    double dept200Pay, dept200Ins, dept200Fica, dept200Medicare, dept200Tax, dept200Dues, dept200Net;
    double dept300Pay, dept300Ins, dept300Fica, dept300Medicare, dept300Tax, dept300Dues, dept300Net;
   
    typedef struct {
       int department;
       char name[10];
       double rate;
       double hours;
       double insurance;
       double ytd;
       int code;
       } record; /*Ends structure department*/
       record employee;
   
    printf("%-10s\n%-10s\n", "Weekly Payroll Register", "by: Brad Widger");
    printf("%-6s%-2s%-30s%-3s%-5s", "Employee", "Gross", "Federal.", "Union", "Net");
    printf("Dept.%-4s%-7s%-4s%-3s%-4s%-5s%-6s%-6s", "Name", "Pay", "Insurance", "FICA", "MEDICARE", "Tax",
    "Dues", "Pay");
    printf("------------------------------------------------------------");
   
    while (!feof(payPtr)) {
    fscan(payPtr, "%d%s%lf%lf%lf%lf", &employee.department, &employee.name, &employee.rate,
    &employee.hours, &employee.insurance, &employee.ytd);
     /*end while*/
                    
                    
        if (employee.hours > 40) {
           pay = employee.rate * employee.hours;
           hoursOver = employee.rate - 40;
           pay = pay - (hoursOver * employee.rate) + (hoursOver * (employee.rate * 1.5));
              } /*end if*/
              else {
                   pay = employee.rate * employee.hours;
                   } /*end else*/
       
        if (employee.ytd > 65000.00) {
           fica = .05 * pay;
           medicare = .02 * pay;
           } /*end if*/
           else {
                fica = .07 * pay;
                medicare = .03 * pay;
                } /*end else*/
       
        tax = pay * .25;
       
        if (employee.code = 1) {
           dues = 35.00;
           } /*end if*/
           else {
                dues = 0.00;
                } /*end else*/
               
        net = pay - employee.insurance - fica - medicare - tax - dues;
       
        if (employee.department = 200) {
           printf("%d%s%lf%lf%lf%lf%lf%lf%lf", &employee.department, employee.name, &pay,
           &employee.insurance, &fica, &medicare, &tax, &dues, &net);
           dept200Pay =+ pay;
           dept200Ins =+ employee.insurance;
           dept200Fica =+ fica;
           dept200Medicare =+ medicare;
           dept200Tax =+ tax;
           dept200Dues =+ dues;
           dept200Net =+ net;
           } /*end if*/

        if (employee.department = 300) {
           printf("%d%s%lf%lf%lf%lf%lf%lf%lf", &employee.department, employee.name, &pay,
           &employee.insurance, &fica, &medicare, &tax, &dues, &net);
           dept300Pay =+ pay;
           dept300Ins =+ employee.insurance;
           dept300Fica =+ fica;
           dept300Medicare =+ medicare;
           dept300Tax =+ tax;
           dept300Dues =+ dues;
           dept300Net =+ net;
           } /*end if*/
          
 
  } /*end while*/
 
  /*fclose(payPtr);*/
  scanf("%d", &test); /*Stops program from ending*/

return 0;
} /*Ends main*/

Name: Anonymous 2008-05-07 7:46

>>17
say - put a string on standard output
A man page would never say that. It would say write the string to stdout.
The st_ctime and st_mtime fields of the file will be marked for update between the successful execution of say()
The what? Just because in your implementation the members of FILE are named as such, you believe that they are required to have the same name in other implementations? FILE doesn't even need to be a struct.
or a call to exit() or abort().
What about _Exit(), or a return from main?
Upon successful completion, say() returns a non-negative number.
You mean a non-negative value. Not number.

ERRORS

Refer to fputc().

There are no errors in fputc(). A man page would include the section (like fputc(3A))

SEE ALSO

fsay(), fopen(), putc(), stdio(), <stdio.h>.

<stdio.h>? What am I supposed to see in stdio.h? Are you aware that standard C header files need not to be real files in your system? And that their contents have to significance to the programmer whatsoever? Moreover, there is no stdio() function in std C (nor fsay()).

tl;dr FAIL FAIL FAIL

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List