Thread: Windows crashes ?

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    53

    Windows crashes ?

    Hi everyone ! I've started like a few minutes ago and I was trying to make an expression parser. Right now I was just trying to see if I could retrieve all operator signs ( +,-,*,/.... ) but windows is crashing as soon as I've entered something as input, why ?
    Here's the code:
    Code:
    using System ;
    
    namespace Maths
    {
    	public class IO
    	{
    		private static string Equation ;
    		public static void ReadEquation( )
    		{
    			Equation = Console.ReadLine( ) ;
    		}
    		public static void WriteEquation( )
    		{
    			Console.WriteLine( "The equation is: {0}", Equation ) ;
    		}
    		public static string GetEquation( )
    		{
    			return Equation ;
    		}
    	}
    
    	public class Operations
    	{
    		protected static char[] Operators ;
    		protected static int Size ;
    		public static void GetOperators( )
    		{
    			Size = 0 ;
    			for( int i = 0 ; i < Maths.IO.GetEquation( ).Length ; ++i )
    			{
    				char temp = Maths.IO.GetEquation( )[i] ;
    				if( ( temp == '+' ) || ( temp == '-' ) || ( temp == '*' ) || ( temp == '/' ) )
    				{
    						Operators[ Size++ ] = temp ;
    				}
    			}
    		}
    	}
    }
    
    public class MyProject
    {
    	public static void Main( )
    	{
    		Maths.IO.ReadEquation( ) ;
    		Maths.Operations.GetOperators( ) ;
    	}
    }
    PS: I know it looks newbish but it's the case, lol I'm a C# newbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >Operators[ Size++ ] = temp ;

    You don't have any size allocated for operators.

    Maybe a System.Collection.ArrayList is easier to use. It's a list, so you can ad to it whenever you feel like it without allocating space from the start.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    Hi, I have tried what you said and I get the same error, here's the code:
    Code:
    public class Operations
    {
    	protected static System.Collections.ArrayList Operators ;
    	public static void GetOperators( )
    	{
    		for( int i = 0 ; i < Maths.IO.GetEquation( ).Length ; ++i )
    		{
    			char temp = Maths.IO.GetEquation( )[i] ;
    			if( ( temp == '+' ) || ( temp == '-' ) || ( temp == '*' ) || ( temp == '/' ) )
    			{
    					Operators.Add( temp ) ;
    			}
    		}
    	}
    }

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Same basic mistake, you need to allocate the instance:

    protected static System.Collections.ArrayList Operators = new System.Collections.ArrayList();

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    Thank you, it worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM