Need help hashing out an error message.

This is a discussion on Need help hashing out an error message. within the C++ Programming forums, part of the General Programming Boards category; I have created a txt file in order to pull information for this program. This is the error code I ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    69

    Question Need help hashing out an error message.

    I have created a txt file in order to pull information for this program.

    This is the error code I am getting:

    c:\documents and settings\administrator\my documents\visual studio 2005\projects\payroll47\test1.cpp(63) : error C2660: 'fopen_s' : function does not take 2 arguments
    Generating Code...

    Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\payroll47\Debug\BuildLog.htm"
    payroll47 - 2 error(s), 0 warning(s)
    ==

    This is the code lines before 63 and after 63 please help:

    Code:
    //Statements
    	printf("Employee files and payroll register\n");
    //Line 63----------------------------------------------------------------------below		if ((spEmployeeData =fopen_s    "EmployeeDataFile.txt", "a"))== NULL)
    		{
    			printf("\aError opening EmployeeDataFile\n");
    			return 100;
    		} // if open input

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    If the error message had said "Your shoe is untied," would you bother to check your shoe?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Just like brewbuck, I find that this error message is fairly clear:
    Quote Originally Posted by Error
    'fopen_s' : function does not take 2 arguments
    Which part of it is that you don't understand.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    69

    Question Error continued

    Please help me understand
    "EmployeeDateFile.txt" - names the file to be referenced, "r" -references the mode code.

    My question is what are the 2 arguements the error message is referencing.

    brewbuck please give me a break I'm still a beginner and don't know everything. Still learning and of course I would check my shoe but what if I didn't know where to find the shoe?

    Code:
    printf("Employee files and payroll register\n");
    		if ((spEmployeeData = fopen_s ("EmployeeDataFile.txt", "r"))== NULL)
    		{
    			printf("\aError opening EmployeeDataFile\n");
    			return 100;
    		} // if open input

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    69
    all good if you know where to find the shoe. I'm not sure what the error message is refering to as the argument because I thought that the filename and the mode where needed parts of the code??

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by silhoutte75 View Post
    Please help me understand
    "EmployeeDateFile.txt" - names the file to be referenced, "r" -references the mode code.
    And yet the error message is saying that this function does not take 2 arguments. Maybe it takes only 1, maybe it takes 3, who knows. I have no idea what "fopen_s()" is. fopen() is a standard function, fopen_s() is... I have no idea.

    My question is what are the 2 arguements the error message is referencing.
    The filename and the mode. Go find the documentation on this fopen_s() thing.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    69
    Code:
    printf("Employee files and payroll register\n");
    		if ((spEmployeeData = fopen_s ("EmployeeDataFile.txt", "r"))== NULL)
    		{
    			printf("\aError opening EmployeeDataFile\n");
    			return 100;
    		} // if open input
    here is the code if I give you more of the could would you be better able to help?

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    here is the code if I give you more of the could would you be better able to help?[/QUOTE]

    Seeing the definition of this fopen_s() function would help.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    69
    Code:
    /*Program will read EmployeeDataFile and create a payroll register containing
     the following information: 
    		a. Employee number (left-justifed)
    		b. Department
    		c. Pay rate
    		d. Exempt
    		e. Hours worked
    		f. Base pay (pay rate * hours worked)
    	Written by: silhoutte75
    		Date: 11/01/07
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    
    //Function Declarations
    	int getEmployData (FILE* spEmployeeData, int* empolyNum, int* depart, int*payRate,
    						char* exempt, int*hourWork);
    
        void calcPay	  (int payRate, int hourWork, int* payCheck);
    
    	int payrollReg    (FILE* spEmployeeData, int employNum, int depart, int payRate,
    						char exempt, int hourwork, int payCheck);
    /*Program will read EmployeeDataFile and create a payroll register containing
     the following information: 
    		a. Employee number (left-justifed)
    		b. Department
    		c. Pay rate
    		d. Exempt
    		e. Hours worked
    		f. Base pay (pay rate * hours worked)
    	Written by: Angela Curvier
    		Date: 11/01/07
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    //Function Declarations
    	int getEmployData (FILE* spEmployeeData, int* empolyNum, int* depart, int*payRate,
    						char* exempt, int*hourWork);
    
        void calcPay	  (int payRate, int hourWork, int* payCheck);
    
    	int payrollReg    (FILE* spEmployeeData, int employNum, int depart, int payRate, 
    						char exempt, int hourwork, int payCheck);
    
    int main (void)
    {	
    //Local Declarations
    	FILE* spEmployeeData;
    
    	int employNum;
    	int depart;
    	int payRate;
    	char exempt;
    	int hourWork;
    	int payCheck;
    
    //Statements
    	printf("Employee files and payroll register\n");
    		if ((spEmployeeData = fopen_s ("EmployeeDataFile.txt", "r"))== NULL)
    		{
    			printf("\aError opening EmployeeDataFile\n");
    			return 100;
    		} // if open input
    	
    		while (getEmployData (spEmployeeData, &employNum, &depart, &payRate, 
    				&exempt, &hourWork))
    			{ 
    				calcPay (payRate, hourWork, &payCheck);
    				payrollReg (spEmployeeData, employNum, depart, payRate, exempt,
    					hourWork, payCheck);
    			}// while
    
    		fclose(spEmployeeData);
    
    		return 0;
    }//main
    I do appreiciate any insight you might be able to share with me. Please guide me I'm not looking for someone to write the code just enlighten my vision. I am either not understanding something or am lost all together.

    Thanks
    Last edited by silhoutte75; 11-02-2007 at 12:11 PM. Reason: remove personal information

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    This code still doesn't explain what fopen_s() is. Why are you calling that instead of regular fopen()?

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    69
    Because when I use fopen() the compiler gives me this error.

    My errors are reduced to one with a warning. This is why I'm confused.


    c:\documents and settings\administrator\my documents\visual studio 2005\projects\payroll47\payrollproject47.cpp(63) : error C2660: 'fopen_s' : function does not take 2 arguments
    Test1.cpp
    c:\documents and settings\administrator\my documents\visual studio 2005\projects\payroll47\test1.cpp(63) : warning C4996: 'fopen' was declared deprecated
    c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'
    Message: 'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
    c:\documents and settings\administrator\my documents\visual studio 2005\projects\payroll47\test1.cpp(97) : warning C4996: 'fscanf' was declared deprecated
    c:\program files\microsoft visual studio 8\vc\include\stdio.h(249) : see declaration of 'fscanf'
    Message: 'This function or variable may be unsafe. Consider using fscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    fopen_s takes 3 parameters, as defined on the MSDN web-page here:
    http://msdn2.microsoft.com/en-us/lib...e9(VS.80).aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Nov 2007
    Posts
    69
    Matsp,

    How might I adjust this program so that I would not need fopen_s, because I am unsure of how to draw on the third parameter required by fopen_s?

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Put this line right at the start of your source file

    #define _CRT_SECURE_NO_DEPRECATE

    If you have many source files, you can do this inside the project as well. Just goto
    project->settings->pre-processor
    and add that symbol.

    Then you can forget all about M$'s attempts to rewrite the standard and use the normal portable functions which everyone else uses, like fopen()
    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.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    Put this line right at the start of your source file

    #define _CRT_SECURE_NO_DEPRECATE

    If you have many source files, you can do this inside the project as well. Just goto
    project->settings->pre-processor
    and add that symbol.

    Then you can forget all about M$'s attempts to rewrite the standard and use the normal portable functions which everyone else uses, like fopen()
    Yes, I agree with this.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating Linked List Using Hashing and Stack
    By m0ntana in forum C Programming
    Replies: 2
    Last Post: 04-07-2007, 07:11 AM
  2. Hashing, indexing and phonetic normalization for approximate str matching...
    By biterman in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-21-2006, 08:42 AM
  3. Replies: 8
    Last Post: 09-11-2006, 11:26 AM
  4. Double Hashing
    By carrja99 in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2003, 07:36 AM
  5. Bucket hashing
    By Supra in forum C Programming
    Replies: 7
    Last Post: 04-04-2002, 04:43 PM

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