Pointers not opening file

This is a discussion on Pointers not opening file within the C Programming forums, part of the General Programming Boards category; I'm trying to create a program that would first read a list from a data file containing names of people ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    24

    Pointers not opening file

    I'm trying to create a program that would first read a list from a data file containing names of people and their sales and then calculate the amount of commission each person makes. I'm trying to get the program to print the information on the screen and then print the same info on a separate data file but currently the gcc compiler would kill the process.


    Code:
    #include <stdio.h>
    int main(){
    int k;
    char text[81], name[30], surname[30];
    double sale, comission;
    FILE *Inf_1, *Outf_1;
    Inf_1 = fopen("Sales.dat", "r");
    Outf_1 = fopen("Comiss.dat", "w");
    
    if ((Inf_1 == NULL) || (Outf_1 == NULL))
    	{
    		printf("Error opening the file\n");
    		exit(1);
    	}
    while(fgets(text,81,Inf_1)!=NULL)
    	{
    		k++;
    		if (k%2 !=) {
    		   sscanf(text, "%s %s", name, surname);
    		else
    		{
    		 sscanf(text, "%lf", &sale);
    		 if (sale <= 25000) {
    			comission = sale * .06;
                 }
    		 if (sale > 25000 && sale <= 50000) {
    			comission = sale * .09;
                 }
    		 if (sale > 50000 && sale <= 80000) {
    			comission = sale * .12;
                 }
    		 if (sale > 80000) {
    			comission = sale * .14;
                 }
    		printf("\n%s %s\n", name,surname);
    		printf("The comission of Mr/Ms %s is %f, based on the sale of %f\n", surname, comission, sale);
    		fprintf(Outf_1, "The comission of Mr/Ms %s is %f, based on the sale of %f\n", surname, comission, sale);
                      }
      }
    	fclose(Inf_1);
    	fclose(Outf_1);
    	exit(0);
    }
    }
    DevC++ is giving me the following errors:
    18 hw6.c
    parse error before `)'
    40 hw6.c
    warning: parameter names (without types) in function declaration
    40 hw6.c
    warning: data definition has no type or storage class
    41 hw6.c
    warning: parameter names (without types) in function declaration
    42 hw6.c
    parse error before `0'
    42 hw6.c
    warning: data definition has no type or storage class

    I am currently in the middle of solving the bracket issues (at this moment, not very good at formatting on a UNIX platform) but I'm not sure how to solve the data definition errors. Any input?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    This line of code is incomplete:
    Code:
    if (k&#37;2 !=) {
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    And, if you fix your indentation, you will see your braces are not placed properly.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    24
    ... damn.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    A development process

    Code:
    for ( ; ; ) {
    }
    while ( 0 ) {
    }
    if ( 0 ) {
    }
    Believe it or not, this will compile.

    What it does mean is that your ( ) and { } are NEVER out of balance. Sure it's a few extra cursor movements (if you don't have a smart code editor which auto-inserts the construct for you), but it sure beats spending hours of "hunt the missing }" in a chaotically indented program, then giving up and posting the whole mess on a message board for someone else to figure out.

    The same goes for "" and /**/ and #if/#endif as well.
    If you keep them balanced from the outset, then you don't have to keep a mental stack of what the current nesting level is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21