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

Pages: 1-

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 3:09

They still give that problem?

Name: Anonymous 2008-05-07 3:11

[quote]fscan[/quote]
LOLWUT?

Name: D: 2008-05-07 3:30

*facepalm* Thanks, I'm an idiot. How I let that go by unscene for so long is beyond me. When I throw that into a compiler, all it does is run 0's forever. Any idea what else could be wrong with it? Here's the data in payroll.txt if it helps.

200 JAdams 25.900000 40.000000 50.060000 500000.000000 1
200 SJones 20.950000 48.500000 4.000000 132000.000000 2
200 JSmith 11.900000 3.500000 10.020000 12000.000000 2
300 FBayes 13.450000 59.800000 9.900000 64419.500000 2
300 HCalvin 7.900000 36.700000 10.000000 0.000000 1

Name: Anonymous 2008-05-07 3:41

Are you dyslexic?  I can't help but notice how like every character in the entire program is in a nonsensical position.  And stop trying to print all those pointers.

Name: Anonymous 2008-05-07 3:49

>>4
200 SJones 20.950000 48.500000 4.000000 132000.000000 2
I lol'd. GUys, we're being trolled.

Name: Anonymous 2008-05-07 4:02

>>6
No, he's actually that stupid. Trust me.

Name: Anonymous 2008-05-07 4:13

>>6
Wouldn't that be SPeyton?

Name: Anonymous 2008-05-07 4:26

:( I am that stupid, unfortunately. And if any trolling is done, it's done by my teacher heh. I didn't make up payroll.txt, she did.

Name: Anonymous 2008-05-07 4:28

>>9
NO FEMALE PROGRAMMERS.

Name: Anonymous 2008-05-07 4:37

You're wasting way too much whitespace. It breaks the flow. Same with the deep indentation.

Name: Anonymous 2008-05-07 4:54

printf("------------------------------------------------------------");

Name: Anonymous 2008-05-07 4:58

LINE BREAKS MOTHERFUCKER, DO YOU KNOW THEM‽

Name: Cudder !MhMRSATORI 2008-05-07 5:10

>>10
O RLY?

Name: Anonymous 2008-05-07 5:18

does c hav operater tht proitns trext and adds enter like in go to next line ghuh"?

Name: Anonymous 2008-05-07 6:22

>>14
If Anonix is any indication, YA RLY.

Name: Anonymous 2008-05-07 6:30

>>15
NAME

    say - put a string on standard output

 SYNOPSIS

    #include <stdio.h>

    int say(const char *s);

 DESCRIPTION

    The say() function writes the string pointed to by s, followed by a
    newline character, to the standard output stream stdout. The terminating
    null byte is not written.

    The st_ctime and st_mtime fields of the file will be marked for update
    between the successful execution of say() and the next successful
    completion of a call to fflush() or fclose() on the same stream or a call
    to exit() or abort().

 RETURN VALUE

    Upon successful completion, say() returns a non-negative number. Otherwise
    it returns EOF, sets an error indicator for the stream and errno is set to
    indicate the error.

 ERRORS

    Refer to fputc().

 EXAMPLES

    None.

 SEE ALSO

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

DERIVATION

    Derived from Issue 1 of the SVID.

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

Name: Anonymous 2008-05-07 7:52

>>18
>Moreover, there is no stdio() function in std C (nor fsay())
NOR say, DUMBASS! HOW ABOUT USING YOUR BRAIN FIRS HUH?
This is a http://www.opengroup.org/onlinepubs/007908799/xsh/puts.html page, where I replaced puts with say, because i fucking love Perl's new say function.

Name: Anonymous 2008-05-07 8:08

>>18
lrn2C

Name: Anonymous 2008-05-07 8:49

>>19
int say( const char *c ) {
    return printf( "%s\n", c );
}

Name: Anonymous 2008-05-07 8:56

>>19
Why use SuSv2? Use an updated paper. Let's see what SuSv3 has to say about it:
http://www.opengroup.org/onlinepubs/009695399/functions/puts.html
Issue 6:

Extensions beyond the ISO C standard are marked.


Guess what's marked. That comment about st_ctime and st_mtime.
Moreover, it's talking about struct stat, and not FILE. There's no 'struct stat' in ISO C.
SuS is known for its horrid pages anyway.
NOR say, DUMBASS! HOW ABOUT USING YOUR BRAIN FIRS HUH?
firs? what firs?
>>20
I challenge you to ask me a POSIX/ISO C question, if I don't answer it in the next 1 with 2 hours (because I usually browse other sites and forget my pending posts here), then consider me a fool.

Name: Anonymous 2008-05-07 9:02

>>21
printf() doesn't return EOF on error, it returns a negative value, and you break say()'s functionality, as described by that faggot >>17

Name: Anonymous 2008-05-07 9:14

>>22
Is this somehow related to my post (>>17; about Perl's brilliant say function), or is that just your way of saying "IVE READ KNR"?

P.S.: I already consider you a fool, no need for a POSIX/ISO C question.

Name: Anonymous 2008-05-07 10:23

>>17

SAY(1)                                           Speech Synthesis Manager                                           SAY(1)

NAME
       say - Convert text to audible speech

SYNOPSIS
           say [-v voice] [-o out.aiff | -n name:port ] [-f file | string ...]

DESCRIPTION
       This tool uses the Speech Synthesis manager to convert input text to audible speech and either play it through the
       sound output device chosen in System Preferences or save it to an AIFF file.

OPTIONS
       string
           Specify the text to speak on the command line. This can consist of multiple arguments, which are considered to
           be separated by spaces.

       -f file
           Specify a file to be spoken. If file is - or neither this parameter nor a message is specified, read from
           standard input.

       -v voice
           Specify the voice to be used. Default is the voice selected in System Preferences.

       -o out.aiff
           Specify an AIFF file to be written.

       -n name
       -n name:port
       -n :port
       -n :
           Specify a service name (default "AUNetSend") and/or IP port to be used for redirecting the speech output
           through AUNetSend.

       If the input is a TTY, text is spoken line by line, and the output file, if specified, will only contain audio for
       the last line of the input.  Otherwise, text is spoken all at once.

ERRORS
       say returns 0 if the text was spoken successfully, otherwise non-zero.  Diagnostic messages will be printed to
       standard error.

1.0                                                     2007-05-11                                                  SAY(1)

Name: Anonymous 2008-05-07 12:17

>>25

$ man say
No manual entry for say

Name: Anonymous 2008-05-07 23:55

>>26
It's okay. That mean you're not a fag. macfag.

Name: Sgt.Kabukiman瓶켍 2012-05-23 5:25

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

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