CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Join Date
    Mar 2011
    Posts
    20

    [RESOLVED] need help please

    llllllllllllllll
    Last edited by sadam; May 8th, 2011 at 12:18 PM.

  2. #2
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    In ReadFile you should be reading from a file not from the keyboard. Surely those scanf's should be fscanf's. Also drop the ncircles parameter completely as that variable is global as are s and t which can also be dropped.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  3. #3
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    cccc
    Last edited by sadam; May 8th, 2011 at 12:17 PM.

  4. #4
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    the variables you pass into the function are all GLOBAL. that means they can be accessed from everywhere. The only parameter that function needs is the filename. fscanf is slightly different to scanf. it requires a FILE* too. scanf reads only from the keyboard assuming stdin hasn't been redirected.
    At the moment, you open a file for reading, try to get input from the keyboard, then close the file.

    int fscanf ( FILE * stream, const char * format, ... );

    thats the prototype for fscanf. See the first parameter is the file pointer which is why you got that error.
    scanf is equivalent to fscanf( stdin, .......... ) which is why it never needs that parameter. its hardwired.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  5. #5
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    fff
    Last edited by sadam; May 8th, 2011 at 12:17 PM.

  6. #6
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    For starters change it to
    Code:
    void ReadFile( const char* filename )
    change the call to ReadFile in main to only pass the filename.
    change the scanf's to fscanf's with the FILE* as the first parameter.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  7. #7
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    oooo
    Last edited by sadam; May 8th, 2011 at 12:17 PM.

  8. #8
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    Give up programming its not for you!
    Code:
    FILE *file;
    if (( file = fopen( filename, "r" )) == NULL )
    Ever going to do anything in particular with that open file pointed to by the FILE* called file??
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  9. #9
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    [[[[
    Last edited by sadam; May 8th, 2011 at 12:17 PM.

  10. #10
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    btw you will also need to drop the asterix here

    i<*ncircles

    as ncircles is a global int, not an int* so dereferencing it is completely wrong.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  11. #11
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    fscanf( file, .............. )

    how hard can it be. you open the file but never read from it. You have to tell the fscanf where to read from.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  12. #12
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    qqqq
    Last edited by sadam; May 8th, 2011 at 12:16 PM.

  13. #13
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: need help please

    Use your debugger and find out. Learning to debug your code is part of learning to program. work out on pen and paper what values you expect in variables and watch to see whats actually happening as you step through your code. When you see something unexpected, work out what went wrong and fix it.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  14. #14
    Join Date
    Mar 2011
    Posts
    20

    Re: need help please

    aaa
    Last edited by sadam; May 8th, 2011 at 12:16 PM.

  15. #15
    Join Date
    Apr 1999
    Posts
    27,449

    Re: need help please

    Quote Originally Posted by sadam View Post
    that means that my program is wrong? can you help me fix it because the deadline is nearby?
    You wrote the code, therefore you must have known what every variable, function, line of code does.

    Therefore, what is stopping you from debugging your own code? You wrote it, right? So why can't you debug something you wrote? As was stated, learning to debug your programs is part of learning how to program. So asking us to do the work you're supposed to have done is almost and maybe, just as bad as one of us writing the code for you.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 7th, 2011 at 11:46 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured