Problem

This is a discussion on Problem within the C++ Programming forums, part of the General Programming Boards category; A window(general protection exception) pops up when I try to compile this: Code: //Filename: ptch.cpp //Fuction: Patch Testing #include <fstream.h> ...

  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 10: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, 05: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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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