944,052 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2632
  • C RSS
Oct 29th, 2004
0

pls heeeeeeeeelp its urgent.

Expand Post »
Hi
I got one assignment to submit within 2 days.I am suppose to build scanner(lexicle analyser) in c,which will take input from standard input stream and print its class.
for example if I input + it will displya "plus",- "minus"
I have to run this program in unix environment.
program will have main function which will accept character from input stream
and call scanner function to get its type.
I have to use getchar(),putcar() and ungetc() functions for this.
I dont know how to use unggetc function withh stdin(standard input).
there will be buffer which will be difeined globally and can be accessed by all the functions.I also want to know how to compile the and run the file in unix enviornment.
I have lost thhe touch with 'c'.Didntdo it from last 2 years.

code will be somewhat like this
main()
{
char msg [][]={"plus","minus"};....(dont know howto use this,gives error char const too long)int code;
char next;
next=getchar();
putchar(next);
ungetc(next);
code=scanner();
while(code!=EOF)
{
print msg;
print buffer;
code=scanner();
}

int scanner()
{
int code;
char next;
if(next=='+')
{
code=get_plus();
}elseif(next=='-')
{code=get_minus();}
return code;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vrush is offline Offline
2 posts
since Oct 2004
Oct 29th, 2004
0

Re: pls heeeeeeeeelp its urgent.

Nope, sorry I dont know.
Reputation Points: 12
Solved Threads: 0
Posting Pro in Training
Young Teck 06 is offline Offline
440 posts
since Sep 2004
Oct 29th, 2004
0

Re: pls heeeeeeeeelp its urgent.

Please don't name future threads something like this. We don't really care if your issue is urgent to you or not. I don't mean to be rude to you, but you stating your issue is urgent is rude to the forum, and the other members that have been waiting for help.

If you'll PM me a more appropriate title, I'll change it to something else. But again, please don't be so rude in the future.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
Oct 29th, 2004
0

Re: pls heeeeeeeeelp its urgent.

your char msg [][] is an array of arrays of char, but the way you initialize it is as an array of char*'s, so how about:

char *msg[] = {"plus","minus"};

Your scanner routine never sets 'next' to anything, so it would be random. Maybe you meant it to be a parameter?

There's a bunch of other stuff, but this is pseudocode pretty devoid of design, so it's hard to critique.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Oct 29th, 2004
0

Re: pls heeeeeeeeelp its urgent.

>so it's hard to critique
A critique is not difficult at all: "Your code is crap, post something that actually uses C--not whatever it is you think is C--and we'll help." Simple.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 29th, 2004
0

Re: pls heeeeeeeeelp

Thanks Chainsaw I will try declaring it that way.and sorry alc6379.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vrush is offline Offline
2 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Array problem
Next Thread in C Forum Timeline: Problems of looping in saving to a text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC