Thread: mysterious code.......(??)

  1. #1
    Registered User deltabird's Avatar
    Join Date
    Jan 2003
    Posts
    73

    mysterious code.......(??)

    I was talking with someone on ICQ, and we were talking about system commands and such. Then he started to show me some program that worked like the command prompt, or something like that. He wasn't real clear on what it did, but I know it had to do with using the command prompt or an equivalent. He gave me the code for it, but there are errors. Here's the code he gave me:
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <fstream.h>
    #include <stdio.h>
    
    int main()
    {
        FILE *DOS;
    	char line[80];
    	if(fopen == ("DOS.txt", "r") )
    	{
    		if(fgets(line, 80, DOS))
    		{
    			*strcat(line);
    		}
    	}
    
    	fclose(DOS);
        return 0;
    }
    errors:
    Code:
    C:\Documents and Settings\Administrator\Desktop\dos.cpp(10) : error C2446: '==' : no conversion from 'char *' to 'struct _iobuf *(__cdecl *)(const char *,const char *)'
            There is no context in which this conversion is possible
    C:\Documents and Settings\Administrator\Desktop\dos.cpp(10) : error C2040: '==' : 'struct _iobuf *(__cdecl *)(const char *,const char *)' differs in levels of indirection from 'char *'
    Error executing cl.exe.
    Anyone know what this looks like it was intended to do, or how to fix it?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try taking out the ==.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Try taking out the ==.
    Methinks what our Canadian friend, eh, meant to say is change the == to =

    [EDIT]
    Forget what I said. I'm smoking some bad crack.
    I think you want to say something like:
    if (DOS = fopen(...)) {
    //...
    }
    Last edited by LuckY; 04-11-2003 at 02:34 PM.

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Originally posted by LuckY
    Methinks what our Canadian friend, eh, meant to say is change the == to =
    You make me want to hurt myself

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by -KEN-
    You make me want to hurt myself
    same here

    Originally posted by LuckY
    Methinks what our Canadian friend, eh, meant to say is change the == to =
    hmm... doesn't look that way. original code had ==

  6. #6
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Wha... what do you mean ken?
    I--I am sorry... Whatever I did to hurt you, please forgive me... Can you? Can you ever forgive me?

    I'm sorry. So, so sorry.

  7. #7
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Oh my god! Hahaha!

    Okay. I did it for the both of you.. I hurt MYself!

    I guess I've been smoking some bad stuff.

    Pardon my zinger.

    (i looked at it like he typed "fp == fopen(...)")

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The code psoted appears to be using/attempting to use C style file handling to read in file contents to a buffer called line.
    Code:
    //the first four lines use old style headers
    #include <iostream.h>
    #include <string.h>
    #include <fstream.h>
    #include <stdio.h>
    
    int main()
    {
        //this line declares a pointer to type FILE which is the equivalent of an fstream in C++.  The pointer's name is DOS.
    It isn't associated with any file yet.  
        FILE *DOS;
        
        //this line declares a buffer to hold the input read in by the flie pointer
        char line[80];
    
        //this line
        if(fopen == ("DOS.txt", "r") )
        
        //should probably be this:
        if(fopen("DOS.txt", "r");
    
        //which would associate DOS with a file called DOS.txt present in the same working directory as this program.  The file will be open in read mode only.   You can't use DOS to write to the DOS.txt.  If the file is opened successfully, the it will return non-NULL which allows the conditional of the if statement to be resolved to true so that you may actually do something.
        {
            
            //I don't use fgets(), but it seems to be being used here to read  up to 80 char from DOS.txt using DOS and placing it in line.  I have no idea whether this syntax is appropriate or not.
            if(fgets(line, 80, DOS))
            {
    
                //what that asterisk is for is beyond me 
                //likewise there should be two parameters to strcat so I think the next line is unlikely to work.  I think the intent was to 
    concatenate the input until line reaches 80, but the call to fgets(), if the syntax is correct already allowed for that, so who knows
                *strcat(line);
              }
        }
    
        //this dissociates DOS from DOS.txt so you can reuse DOS in this program again if you want to.
        fclose(DOS);
    
        return 0;
    }
    posting this question on the C board may get you more/better answers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM