Thread: characters not found

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    385

    characters not found

    The first two characters of any win32 exe are supposed to be MZ, so when I try to search for these characters using the following code it should output 0 (zero), but instead it outputs "characters not found".
    When I try the same thing using a C code it gives the proper output i.e, zero.

    Can someone please tell me whats wrong??

    Code:
    #include<iostream>
    #include<fstream>
    
    int main()
    {
    	std::fstream file("linked list.exe",std::ios::app|std::ios::binary);
    	if(!file)
    	{
    		std::cout<<"unable to open";
    	}
    
    	int i; char s[2];
    	for(i = 0;;i++)
    	{
    		file.seekg(i);
    		file.read(s,2);
    		
    		if(s[0] == 'M' && s[1] == 'Z')
    		{
    			std::cout<<i;
    			break;
    		}
    
    		if(file.eof())
    		{
    			std::cout<<"Characters not found";
    			break;
    		}
    
    	}
    }
    Last edited by juice; 03-08-2012 at 12:22 AM.

  2. #2
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Also can you please tell how can I open the file linked list.exe if it present on some other drive lets say c:, cause
    Code:
    std::fstream file("c:\linked list.exe",std::ios::app|std::ios::binary);
    does not work.

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Don't you need at least the std::ios::in flag (and possibly the out flag, although that may be implied by app).
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    To answer your second question, you need to put two backslashes in order to get one in a string \\ .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pq - Sq - Kq --- Found!!!
    By sean in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 12-02-2002, 07:07 PM
  2. Look what I found!
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-14-2002, 05:34 AM
  3. EOF not found
    By bif22 in forum C++ Programming
    Replies: 12
    Last Post: 09-29-2002, 04:35 PM
  4. -lqt not found?
    By f0d in forum Linux Programming
    Replies: 2
    Last Post: 06-03-2002, 10:17 AM