473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Need a bit of help with reading in characters.

Hey all, thanks for taking the time to read this in the first place.

Anyway, ill try and keep it simple. In my program, if i type $ man something
it should read in the 2 words, man and something
it should look up man - find that its a function, run the man function, and
then, with that second word "something" it should then execute that as its
parameters, if that make sense.

At the moment, it semi works, i.e If i type man it will run the function i
want, but i cant work out where to go next, im not even sure if the method
is right.. Any ideas?

The way i see it is that the first word/token is the command or function,
the 2nd, maybe third and so on, are its paremeters.
A way to describe it could be if i were to type: dir /p /w so it would run
the dir function, use /p as its first param, and then so on. Hope this makes
sense

Thanks for any advice or ideas.

[Code has been uploaded]

http://tinyurl.com/29u5z

(this code is not my original code and has been provided by a Lecturer with
permission to modify)
Nov 14 '05 #1
7 1547
I am not sure I understand what you're trying to say (yeh....computer
overdose) but from what I see you're having problems evaluating the
parameters of your program. (i.e. you're getting the "dir", but not being
able to analyze "/p").

The problem that you are having might (hehe) be caused by the ~ scanf("%s",
string); ~ line, where you should enter the parameters. Using scanf, if you
type "dir /p" it would first assign "dir" to string, analyze it, run the
block (if any) and then go back with "/p" into string again.

If your problem is simply with how to analyse the parameters, you have to
first check what the user has entered (on the example above, "dir") then
from within that analyze the parameters and possible choices for each (you
might wanna use an dynamic array for that). So if the user has entered "/p"
it would do that, if the user has entered "/y" it would do this, and so
forth.

Hope I've helped you out,
Leo C.
al*********@hotmail.com

"Advocated" <......@......com> escreveu na mensagem
news:SW****************@newsfep4-winn.server.ntli.net...
Hey all, thanks for taking the time to read this in the first place.

Anyway, ill try and keep it simple. In my program, if i type $ man something it should read in the 2 words, man and something
it should look up man - find that its a function, run the man function, and then, with that second word "something" it should then execute that as its
parameters, if that make sense.

At the moment, it semi works, i.e If i type man it will run the function i
want, but i cant work out where to go next, im not even sure if the method
is right.. Any ideas?

The way i see it is that the first word/token is the command or function,
the 2nd, maybe third and so on, are its paremeters.
A way to describe it could be if i were to type: dir /p /w so it would run the dir function, use /p as its first param, and then so on. Hope this makes sense

Thanks for any advice or ideas.

[Code has been uploaded]

http://tinyurl.com/29u5z

(this code is not my original code and has been provided by a Lecturer with permission to modify)

Nov 14 '05 #2
On Mon, 22 Dec 2003 00:30:33 -0000
"Advocated" <......@......com> wrote:
Hey all, thanks for taking the time to read this in the first place.

Anyway, ill try and keep it simple. In my program, if i type $ man > something
it should read in the 2 words, man and something
it should look up man - find that its a function, run the man > function, and
then, with that second word "something" it should then execute that as > its
parameters, if that make sense.


at first i thought you were confusing command-line parameters (argv[])
with function parameters. after looking at the code, it looks more
like a proto-shell of sorts. if that is the case, then look into
strtok(3) to "tokenize" the contents of string.

after that, you should declare main() as type int, lose the infinite
loop, return from main(), and ditch the c++ style comments.

--
donLouis
Nov 14 '05 #3

"lcustoc611" <lc********@rogers.com> wrote in message
news:Hr********************@news01.bloor.is.net.ca ble.rogers.com...
I am not sure I understand what you're trying to say (yeh....computer
overdose) but from what I see you're having problems evaluating the
parameters of your program. (i.e. you're getting the "dir", but not being
able to analyze "/p").

The problem that you are having might (hehe) be caused by the ~ scanf("%s", string); ~ line, where you should enter the parameters. Using scanf, if you type "dir /p" it would first assign "dir" to string, analyze it, run the
block (if any) and then go back with "/p" into string again.

If your problem is simply with how to analyse the parameters, you have to
first check what the user has entered (on the example above, "dir") then
from within that analyze the parameters and possible choices for each (you
might wanna use an dynamic array for that). So if the user has entered "/p" it would do that, if the user has entered "/y" it would do this, and so
forth.

Hope I've helped you out,
Leo C.
al*********@hotmail.com


<snip>
http://tinyurl.com/29u5z

<snip>

What i think you are saying is create something which recognises the
parameters, i.e make something for each possible parameter. The problem with
this is, my program will be running external commands too, so it would be
impossible to tell what the user will type? Is this what you mean?

Cheers for the reply too
Nov 14 '05 #4
> > Hey all, thanks for taking the time to read this in the first place.

Anyway, ill try and keep it simple. In my program, if i type $ man > something it should read in the 2 words, man and something
it should look up man - find that its a function, run the man > function, and then, with that second word "something" it should then execute that as > its parameters, if that make sense.


at first i thought you were confusing command-line parameters (argv[])
with function parameters. after looking at the code, it looks more
like a proto-shell of sorts. if that is the case, then look into
strtok(3) to "tokenize" the contents of string.

after that, you should declare main() as type int, lose the infinite
loop, return from main(), and ditch the c++ style comments.

--
donLouis


Well i think i get what you mean, this is the original code i was looking
at:
http://tinyurl.com/39nfe

I think this uses a kind of tokeniser, but the problem is, the input is
predifined if that makes any sense, i.e
strcpy(InputString," Test\t \t of the parser \t with its problems....
a");
is already the user input, instead of getting the actual user input.

The idea is, it will actually be a kind of shell, if i can get this first
part to function. Any more ideas?

Thanks
Nov 14 '05 #5
On Mon, 22 Dec 2003 09:30:33 -0000
"Advocated" <......@......com> wrote:
I think this uses a kind of tokeniser, but the problem is, the input >is
predifined if that makes any sense, i.e
strcpy(InputString," Test\t \t of the parser \t with its >problems....
a");
is already the user input, instead of getting the actual user input.

The idea is, it will actually be a kind of shell, if i can get this first
part to function. Any more ideas?


back up to the scanf of string. the program _immediately_ runs string
through findCmd. if i type in man or dir, it indexes the function
properly. if i type in foobar, i get an "Unknown command" as expected.
if i type in man foobar, i get the output for man _and_ the output for
an unknown command.

_if_, what you are looking for is something like "running man w/ foobar
parameters", _then_, you need to break up string into an array of chars
similar to argv[] _before_ it runs through findCmd or any other parsers,
i.e. first you lex it, second you yacc it, then you run it.

if this is not what you are looking for, then i am babbling incoherently
and i apologize for wasting your time.

--
donLouis
Nov 14 '05 #6
I still don't understand what you're trying to do, but let's see if with a
few more examples we all get it.
Are you trying to create a program that, when running, would accept
arguments and would pass them to the shell?
Because you've mentioned something earlier about your program being able to
accept external arguments as well (ie. myprogram -a -x -kill) but it does
not do that so far.

If your program will take external parameters, you might wanna have a look
at the main function and change it to something like ~ int main(int argc,
char * argv[]) ~ and analyze all the parameters from it and pass them back
to the shell.

If what you're trying to do is simply get parameters at runtime (ie. your
software prompts for user imput and you will then analyze them), you have to
change that scanf input type ~ scanf("%s", string); ~ as i've said before
and make it accept the whole line. Afterwards, you separate them and check
any arguments, enabling flags for each parameter and then running your
program according to the flags.

Leo
al*********@hotmail.com

"Advocated" <......@......com> escreveu na mensagem
news:7R****************@newsfep4-winn.server.ntli.net...
Hey all, thanks for taking the time to read this in the first place.

Anyway, ill try and keep it simple. In my program, if i type $ man > something it should read in the 2 words, man and something
it should look up man - find that its a function, run the man > function, and then, with that second word "something" it should then execute that as
its parameters, if that make sense.


at first i thought you were confusing command-line parameters (argv[])
with function parameters. after looking at the code, it looks more
like a proto-shell of sorts. if that is the case, then look into
strtok(3) to "tokenize" the contents of string.

after that, you should declare main() as type int, lose the infinite
loop, return from main(), and ditch the c++ style comments.

--
donLouis


Well i think i get what you mean, this is the original code i was looking
at:
http://tinyurl.com/39nfe

I think this uses a kind of tokeniser, but the problem is, the input is
predifined if that makes any sense, i.e
strcpy(InputString," Test\t \t of the parser \t with its problems....
a");
is already the user input, instead of getting the actual user input.

The idea is, it will actually be a kind of shell, if i can get this first
part to function. Any more ideas?

Thanks

Nov 14 '05 #7

"Leo Custodio" <lc********@rogers.com> wrote in message
news:8b********************@news04.bloor.is.net.ca ble.rogers.com...
I still don't understand what you're trying to do, but let's see if with a
few more examples we all get it.
Are you trying to create a program that, when running, would accept
arguments and would pass them to the shell?
Because you've mentioned something earlier about your program being able to accept external arguments as well (ie. myprogram -a -x -kill) but it does
not do that so far.

If your program will take external parameters, you might wanna have a look
at the main function and change it to something like ~ int main(int argc,
char * argv[]) ~ and analyze all the parameters from it and pass them back
to the shell.

If what you're trying to do is simply get parameters at runtime (ie. your
software prompts for user imput and you will then analyze them), you have to change that scanf input type ~ scanf("%s", string); ~ as i've said before
and make it accept the whole line. Afterwards, you separate them and check
any arguments, enabling flags for each parameter and then running your
program according to the flags.

Leo
al*********@hotmail.com

"Advocated" <......@......com> escreveu na mensagem
news:7R****************@newsfep4-winn.server.ntli.net...
> Hey all, thanks for taking the time to read this in the first place.
>
> Anyway, ill try and keep it simple. In my program, if i type $ man >

something
> it should read in the 2 words, man and something
> it should look up man - find that its a function, run the man >

function, and
> then, with that second word "something" it should then execute that
as
its
> parameters, if that make sense.

at first i thought you were confusing command-line parameters (argv[])
with function parameters. after looking at the code, it looks more
like a proto-shell of sorts. if that is the case, then look into
strtok(3) to "tokenize" the contents of string.

after that, you should declare main() as type int, lose the infinite
loop, return from main(), and ditch the c++ style comments.

--
donLouis


Well i think i get what you mean, this is the original code i was looking at:
http://tinyurl.com/39nfe

I think this uses a kind of tokeniser, but the problem is, the input is
predifined if that makes any sense, i.e
strcpy(InputString," Test\t \t of the parser \t with its problems.... a");
is already the user input, instead of getting the actual user input.

The idea is, it will actually be a kind of shell, if i can get this first part to function. Any more ideas?

Thanks



Thanks for all this help guys. Ive made the changes stated
http://tinyurl.com/2hkpx
and also added something to get the commands, this is working ok at the
moment, in the means that, if i type: dir *.exe it will print token 0 is
dir, token 1 is *.exe so i think im kind of getting the idea?

Im having a silly problem with it though, in the LeftTrim function it uses:
while ((*Input == ' ') || (*Input == '\t')) This is supposed to remove all
spaces and tabs from the input, but its only semi working and i cannot see
why. If i type hello<space>world it works fine, if i do
hello<space><space>world etc, it works fine, and both times prints token 0 =
hello token 1 = world.
The problem is with the tabs. If i type: <tab>hello world it prints token 0
= hello token 1 = world. but if i type: hello<tab>world it prints: token 0
= hello world.

Not sure why its not working, but in my previous examples where i wasnt
waiting for user input(using a predefined string: strcpy(InputString,"
Test\t \t of the parser \t with its problems.... a"); ) it worked
perfectly, Can anyone see where im going wrong? Ive tried running in Visual
Studio debugger, but for some reason its not working 100%, i.e i run the
debugger, it gets to say a printf statement and asks me where printf.c is
located :s

Cheers though all!

Nov 14 '05 #8

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

Similar topics

38
by: lawrence | last post by:
I'm just now trying to give my site a character encoding of UTF-8. The site has been built in a hodge-podge way over the last 6 years. The validator tells me I've lots of characters that don't...
15
by: honeygrl33 | last post by:
i accidentially erased something someone helped me write and i am soooo in trouble if i dont fix this, i really need the help!!!!! heres what i have: /* */ #include <stdio.h> #include...
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
2
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about...
8
by: bahoo | last post by:
Hi, I have a text file containing a single line of text, such as 0024 How should I read it into a "list"? I tried this, but the "join" did not work as expected. Any suggestions?
2
by: GHUM | last post by:
Hello, I am pylinting some software of mine. Now pylint throws messages, and I know of pylint --help-msg to get some more text. What is missing out are explanation, WHY some things are bad,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.