Thread: Problem

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Post Problem

    A window(general protection exception) pops up when I try to compile this:

    Code:
    //Filename: ptch.cpp
    //Fuction: Patch Testing
    #include <fstream.h>
    #include <conio.h>
    #include <string.h>
    #include <stdio.h>
    int main(void)
    {
    	char *p;
    	char input[100];
    	ifstream b_file("patch.txt");
    	b_file >> input;
    	b_file.close();
    	int lp=1;
    	while(lp!=0)
    	{
    		char nl[]="\n";
    		strcpy(p,nl);
          lp=lp-1;
    	}
    	p = strtok(input, "2");
    	if(p) cout << p;
    	clrscr();
    	p = strtok(NULL, "2");
    	cout << p;
    	getch();
    }
    The notepad file(in the same directory) says this:

    Code:
    A1Star
    M2Wars
    What's wrong?
    Last edited by drdroid; 05-25-2002 at 09:29 AM.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    A pointer that points to nothing or a random memory location isn't much use. You need to point p at some area of memory before you can use it. Apart from that I'm not really sure what you're trying to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM