473,796 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid token .... Very Very simply program, why do I get this?

I'm using 2002.Net, 1.0 framwork.

I am basically learning C# so I wrote this and get invalid token
errors. Does anyone see why?

using System;
namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.maxSize ; ++i)
{
Console.Write(" Pushing [" + stack.Push(i+10 )+ "]") ;
Console.WriteLi ne(" now Top becomes: " + stack._top) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.maxSize ; ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.maxSize) ;
Console.WriteLi ne("Content: " + stack.Pop()) ;
}
}
}
}

using System;

namespace ConsoleApplicat ion2
{

class stack
{

//ERRORS BEGIN HERE SUCH AS "Invalid
token ";" in the private _top; line.
private _top;
public int const maxsize = 10;
private _arr[maxSize];

public stack()
{
_top = 0;

}

void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
break;
}
}

int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
break;
}
}
{}
}
}

Feb 9 '06 #1
9 2703
You haven't defined the type of _top. The compiler doesn't know what it
is.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Ne****@gmail.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I'm using 2002.Net, 1.0 framwork.

I am basically learning C# so I wrote this and get invalid token
errors. Does anyone see why?

using System;
namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.maxSize ; ++i)
{
Console.Write(" Pushing [" + stack.Push(i+10 )+ "]") ;
Console.WriteLi ne(" now Top becomes: " + stack._top) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.maxSize ; ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.maxSize) ;
Console.WriteLi ne("Content: " + stack.Pop()) ;
}
}
}
}

using System;

namespace ConsoleApplicat ion2
{

class stack
{

//ERRORS BEGIN HERE SUCH AS "Invalid
token ";" in the private _top; line.
private _top;
public int const maxsize = 10;
private _arr[maxSize];

public stack()
{
_top = 0;

}

void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
break;
}
}

int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
break;
}
}
{}
}
}

Feb 9 '06 #2
A variable must have a type, as far as I know :'-(

Instead of:
private _top;
Use:
private int _top;

<Ne****@gmail.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I'm using 2002.Net, 1.0 framwork.

I am basically learning C# so I wrote this and get invalid token
errors. Does anyone see why?

using System;
namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.maxSize ; ++i)
{
Console.Write(" Pushing [" + stack.Push(i+10 )+ "]") ;
Console.WriteLi ne(" now Top becomes: " + stack._top) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.maxSize ; ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.maxSize) ;
Console.WriteLi ne("Content: " + stack.Pop()) ;
}
}
}
}

using System;

namespace ConsoleApplicat ion2
{

class stack
{

//ERRORS BEGIN HERE SUCH AS "Invalid
token ";" in the private _top; line.
private _top;
public int const maxsize = 10;
private _arr[maxSize];

public stack()
{
_top = 0;

}

void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
break;
}
}

int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
break;
}
}
{}
}
}

Feb 9 '06 #3
You get the error because in the cases of _top and _arr you don't say
what type they are.

You can't just say: "private _top;" you have to say something like
"private int _top;"

Feb 9 '06 #4
Additionally, your const statement should come before the type.
Finally, your array declaration should look like this:

private int[] _arr;
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Ne****@gmail.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I'm using 2002.Net, 1.0 framwork.

I am basically learning C# so I wrote this and get invalid token
errors. Does anyone see why?

using System;
namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.maxSize ; ++i)
{
Console.Write(" Pushing [" + stack.Push(i+10 )+ "]") ;
Console.WriteLi ne(" now Top becomes: " + stack._top) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.maxSize ; ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.maxSize) ;
Console.WriteLi ne("Content: " + stack.Pop()) ;
}
}
}
}

using System;

namespace ConsoleApplicat ion2
{

class stack
{

//ERRORS BEGIN HERE SUCH AS "Invalid
token ";" in the private _top; line.
private _top;
public int const maxsize = 10;
private _arr[maxSize];

public stack()
{
_top = 0;

}

void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
break;
}
}

int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
break;
}
}
{}
}
}

Feb 9 '06 #5
You have

private _top;

You seem to have forgotten to declare what type of field _top is. Try

private int _top;


"Ne****@gmail.c om" wrote:
I'm using 2002.Net, 1.0 framwork.

I am basically learning C# so I wrote this and get invalid token
errors. Does anyone see why?

using System;
namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.maxSize ; ++i)
{
Console.Write(" Pushing [" + stack.Push(i+10 )+ "]") ;
Console.WriteLi ne(" now Top becomes: " + stack._top) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.maxSize ; ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.maxSize) ;
Console.WriteLi ne("Content: " + stack.Pop()) ;
}
}
}
}

using System;

namespace ConsoleApplicat ion2
{

class stack
{

//ERRORS BEGIN HERE SUCH AS "Invalid
token ";" in the private _top; line.
private _top;
public int const maxsize = 10;
private _arr[maxSize];

public stack()
{
_top = 0;

}

void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
break;
}
}

int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
break;
}
}
{}
}
}

Feb 9 '06 #6
Thanks, I new it was something simple. I got this example of the web
(http://www.c-sharpcorner.com/Languag...tionInCSDS.asp)
and thought I fool around with it. Too bad it had errors in it.

Feb 9 '06 #7
In fact...
"Csharper" <Ne****@gmail.c om> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
Thanks, I new it was something simple. I got this example of the web
(http://www.c-sharpcorner.com/Languag...tionInCSDS.asp)
and thought I fool around with it. Too bad it had errors in it.

Feb 9 '06 #8
Apparently there were other errors in the example code I used. The
follow code works now:

using System;

namespace ConsoleApplicat ion2
{
class Class1
{
static void Main(string[] args)
{
Stack stack = new Stack() ;
int i = 0 ;
for (; i<stack.getSize (); ++i)
{
stack.push(i+10 );
Console.Write(" Pushing [" + (i+10) + "]") ;
Console.WriteLi ne(" now Top becomes: " + stack.getTop()) ;
Console.WriteLi ne() ;
}

int j = 0 ;
for (; j<stack.getSize (); ++j)
{
Console.Write(" Popping [" + j + "] of " + stack.getSize() ) ;
Console.WriteLi ne("Content: " + stack.pop()) ;
}
}
}

}
using System;

namespace ConsoleApplicat ion2
{
public class Stack
{
private int _top;
public const int maxSize = 10;
private int[] _arr = new int[maxSize];

public Stack()
{
_top = 0;

}

public int getTop()
{
return _top;
}

public int getSize()
{
return maxSize;
}

public void push (int val)
{
if (_top < maxSize)
{
_arr[_top] = val;
++_top;
}
else
{
}
}

public int pop()
{
if (_top > 0)
{
--_top;
return _arr[_top];
}
else
{
return 0;
}
}
}
}

Feb 9 '06 #9
Ouch. They really should test their code before they post it in an
article. That's embarrassing, especially when they build the program up
line by line, with the same error persisting throughout the article.

Feb 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
7613
by: Ian Lazarus | last post by:
Hello. How do "unresolved token" link errors occur. How do I fix them? Linking... LINK : error LNK2020: unresolved token (0A000015) ??_7type_info@@6B@ LINK : error LNK2020: unresolved token (0A000016) _CxxThrowException LINK : error LNK2020: unresolved token (0A000018) exception.__ctor LINK : error LNK2020: unresolved token (0A000019) exception.__ctor LINK : error LNK2020: unresolved token (0A00001A) exception.__dtor LINK : error...
4
13611
by: Eric Lilja | last post by:
Is this an invalid program? Doesn't compile on my system: #include <cstdio> class Why { enum TArch {LITTLE_ENDIAN, BIG_ENDIAN, NON_IEEE}; TArch Architecture; }; int
9
2165
by: Sebouh | last post by:
I'm very close of shooting myself in the head right now. Why in hell does free(xx) give me an error: *** glibc detected *** free(): invalid pointer: 0x08ce6158 *** // The function returns something like the argv parameter in main. char** parser (char* ch) { char** xx = NULL; char* temp; // contains the input which will be modified when using strtok int length = strlen (ch); // length of the string char* token;
4
2208
by: Mamluk Caliph | last post by:
For quite some time I've used code as the following to be able to "cut&paste" parts from different headerfiles of the same name. It has worked with GCC, MS, Borland, Keil to name a few. In principle the mechanism looks like this: #define CHAINPATH /usr/include #define DEFSTR( x ) \ #x
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.