473,799 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1585
I am not sure I understand what you're trying to say (yeh....compute r
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*********@hot mail.com

"Advocated" <......@......c om> escreveu na mensagem
news:SW******** ********@newsfe p4-winn.server.ntl i.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" <......@......c om> 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********@rog ers.com> wrote in message
news:Hr******** ************@ne ws01.bloor.is.n et.cable.rogers .com...
I am not sure I understand what you're trying to say (yeh....compute r
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*********@hot mail.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(InputStr ing," 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" <......@......c om> 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(InputStr ing," 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*********@hot mail.com

"Advocated" <......@......c om> escreveu na mensagem
news:7R******** ********@newsfe p4-winn.server.ntl i.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(InputStr ing," 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********@rog ers.com> wrote in message
news:8b******** ************@ne ws04.bloor.is.n et.cable.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*********@hot mail.com

"Advocated" <......@......c om> escreveu na mensagem
news:7R******** ********@newsfe p4-winn.server.ntl i.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(InputStr ing," 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>wor ld it works fine, if i do
hello<space><sp ace>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(InputStr ing,"
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
2860
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 belong to the UTF-8 encoding. Other than changing them by hand, can anyone think of a clever way to find and convert these characters? http://validator.w3.org/check?uri=http%3A%2F%2Fwww.krubner.com%2F
15
386
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 <stdlib.h>
2
3253
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 between plain ASCII files I receive and the Unicode ones would be to check if the first two bytes read 0xFFFE. But nothing I do seems to be able to do that. I tried reading it in binary mode and reading two characters in:
9
2356
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 delimiting characters can be specified on the command line. The default delimiting characters built into the program are space, newline, tab, carriage return, form feed, vertical tab, comma and null. If a 'u' or 'U' is specified as the last command line...
40
3251
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, including asian languages (chinese, japanese, korean, etc). First of all, strings will be passed to my class methods, some of which based on the language (and on the encoding) might contain characters that require more that a single byte.
66
5420
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 occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
8
2752
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 the sequence nos and it should be such that i can access it through the structure .plz help me .
2
1814
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 your characters into that save file. Anyhow, I want to extract a couple of lines of it and save it into a database and I need help on figuring out a good way of reading the file. The problem is that the file can look pretty different depending...
8
2003
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
12345
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, so I am searching for explanations and ways to improve my code: Example:
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.