Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > c program - command line prompt - need help

Reply
Thread Tools

c program - command line prompt - need help

 
 
raeiko
Guest
Posts: n/a
 
      03-01-2009
Hello guys,

i urgently need your help

I have to write a C program that reads a series of strings and prints
only those that end with the letters ed. To enter the string i
should use the command line prompt and when i press the return key,
the program should print the string if it ends in "ed" and prompt for
another string if it doesn't.

My problem is that, even after reading from Dietel book and searching
in internet, I didn't get how to use the command line prompt...

Could you be so kind to give me some hints to start from?

Thanks in advance for your help,

 
Reply With Quote
 
 
 
 
Spiros Bousbouras
Guest
Posts: n/a
 
      03-01-2009
On 1 Mar, 23:07, raeiko <(E-Mail Removed)> wrote:
> Hello guys,
>
> i urgently need your help


Left homework for the last moment , have we ?

> I have to write a C program that reads a series of strings and prints
> only those that end with the letters ed. To enter the string i
> should use the command line prompt and when i press the return key,
> the program should print the string if it ends in "ed" and prompt for
> another string if it doesn't.
>
> My problem is that, even after reading from Dietel book and searching
> in internet, I didn't get how to use the command line prompt...
>
> Could you be so kind to give me some hints to start from?


The right place to start is to describe the problem exactly. The
problem here is that it is unclear what you mean by "command
line prompt". The C standard doesn't say anything about a
"command line prompt" nor have I seen anywhere a description
of C which mentions a "command line prompt". It's not clear
whether you simply mean reading from stdin or whether you
are using some sort of specialised environment where C comes
with a "command line prompt".

Do you know how to do everything else and simply have trouble
with this prompt thingy ?
 
Reply With Quote
 
 
 
 
Curtis Dyer
Guest
Posts: n/a
 
      03-02-2009
raeiko <(E-Mail Removed)> wrote:
> Hello guys,
>
> i urgently need your help
>
> I have to write a C program that reads a series of strings and prints
> only those that end with the letters “ed.” To enter the string i
> should use the command line prompt and when i press the return key,
> the program should print the string if it ends in "ed" and prompt for
> another string if it doesn't.
>
> My problem is that, even after reading from Dietel book and searching
> in internet, I didn't get how to use the command line prompt...
>
> Could you be so kind to give me some hints to start from?


What have you tried so far?

> Thanks in advance for your help,


One option might be using the `fgets()' function in a loop to read
from `stdin', one line at a time. You could then examine the data
for the current line in your loop, and make a decision as to what you
want to do.

Just a bit of a disclaimer, I'm still in the process of learning C as
well.

--
Curtis
s/sig\.invalid/gmail.com/;
 
Reply With Quote
 
Curtis Dyer
Guest
Posts: n/a
 
      03-02-2009
Richard Heathfield <(E-Mail Removed)> wrote:
> raeiko said:
>
> > Hello guys,
> >
> > i urgently need your help
> >
> > I have to write a C program that reads a series of strings and
> > prints only those that end with the letters ?ed.? To enter the
> > string i should use the command line prompt and when i press the
> > return key, the program should print the string if it ends in "ed"
> > and prompt for another string if it doesn't.
> >
> > My problem is that, even after reading from Dietel book and
> > searching in internet, I didn't get how to use the command line
> > prompt...

>
> You seem to be talking about what are usually known as command line
> arguments.
>
> > Could you be so kind to give me some hints to start from?

>
> I think I see what you mean about Deitel and Deitel's explanation.
>
> Okay, here's the basic idea:
>
> We start off by using the other form of main(). You are probably
> accustomed to int main(void), but to gain access to command line
> arguments we need to use this instead:


Perhaps I'm misreading the OP's post still, but it seems like they
want something like getting input from STDIN interactively via a
shell terminal. Despite the OP mentioning not understanding how to
use "the command line prompt", their spec seems doesn't seem to
indicate the need for command line arguments.

This is an excerpt from the OP's spec:

Message-ID: <c45530e9-d711-4101-9458-
http://www.velocityreviews.com/forums/(E-Mail Removed)>
... when i press the return key, the program should print the
string if it ends in "ed" and prompt for another string if it
^^^^^^^^^^^^^^^^^^^^^^^^^
> doesn't.


Sorry if I'm missing something painfully obvious. :-/

<snip>

--
Curtis
s/sig\.invalid/gmail.com/;
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      03-02-2009
Richard Heathfield <(E-Mail Removed)> writes:
> raeiko said:
>
>> Hello guys,
>>
>> i urgently need your help
>>
>> I have to write a C program that reads a series of strings and
>> prints only those that end with the letters ?ed.? To enter the
>> string i should use the command line prompt and when i press the
>> return key, the program should print the string if it ends in "ed"
>> and prompt for another string if it doesn't.
>>
>> My problem is that, even after reading from Dietel book and
>> searching in internet, I didn't get how to use the command line
>> prompt...

>
> You seem to be talking about what are usually known as command line
> arguments.


"...and prompt for another string..." sounds more like stdin to me.
An array of char, and an fgets() call seems to be the order of the day.

Phil
--
I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word! -- pbhj on /.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-02-2009
Richard Heathfield <(E-Mail Removed)> writes:

> Curtis Dyer said:
>
> <snip>
>
>> Perhaps I'm misreading the OP's post still, but it seems like they
>> want something like getting input from STDIN interactively via a
>> shell terminal. Despite the OP mentioning not understanding how to
>> use "the command line prompt", their spec seems doesn't seem to
>> indicate the need for command line arguments.
>>
>> This is an excerpt from the OP's spec:
>>
>> Message-ID: <c45530e9-d711-4101-9458-
>> (E-Mail Removed)>
>> ... when i press the return key, the program should print the
>> string if it ends in "ed" and prompt for another string if it
>> ^^^^^^^^^^^^^^^^^^^^^^^^^
>> > doesn't.

>>
>> Sorry if I'm missing something painfully obvious. :-/

>
> Perhaps we both did. You're right to point out my omission, but now
> I'm wondering whether he needs /both/ - command-line processing
> /and/ standard input processing. (Alternatively, you're right, I'm
> wrong, and I just chased him up a blind alley.)


Why would you wonder that. Requirements analysis is simple enough in this
case because he *specifically* states:

,----
| >> ... when i press the return key, the program should print the
| >> string if it ends in "ed" and prompt for another string if it
`----

It could not be clearer.



 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      03-02-2009
On 1 Mar, 23:07, raeiko <(E-Mail Removed)> wrote:

> i urgently need your help




> I have to write a C program that reads a series of strings and prints
> only those that end with the letters ed. To enter the string i
> should use the command line prompt and when i press the return key,
> the program should print the string if it ends in "ed" and prompt for
> another string if it doesn't.


I think other posters have seriously misunderstood you.
This is plainly an interactive program (no command line arguments
needed)

> My problem is that, even after reading from Dietel book and searching
> in internet, I didn't get how to use the command line prompt...
>
> Could you be so kind to give me some hints to start from?
>
> Thanks in advance for your help,


does this help?

#include <string.h>
#include <stdio.h>

int main (void)
{
for (;
{
char line [1024];
char *nl;

printf ("enter a string: ");
fflush (stdout); /* ensure prompt appears */

/* read a string, halt if get end-of-file */
if (fgets (line, sizeof line, stdin) == NULL)
return 0;

/* halt when get an empty string */
if (line[0] == '\n')
return 0;

/* remove end-of-line */
if ((nl = strchr (line, '\n')) != NULL)
*nl = '\0';

printf ("the string you entered was \"%s\"\n", line);
}

return 0;
}



 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      03-02-2009
On 2 Mar, 00:48, Curtis Dyer <(E-Mail Removed)> wrote:
> raeiko <(E-Mail Removed)> wrote:
> > Hello guys,

>
> > i urgently need your help

>
> > I have to write a C program that reads a series of strings and prints
> > only those that end with the letters ed. To enter the string i
> > should use the command line prompt and when i press the return key,
> > the program should print the string if it ends in "ed" and prompt for
> > another string if it doesn't.

>
> > My problem is that, even after reading from Dietel book and searching
> > in internet, I didn't get how to use the command line prompt...

>
> > Could you be so kind to give me some hints to start from?

>
> What have you tried so far?
>
> > Thanks in advance for your help,

>
> One option might be using the `fgets()' function in a loop to read
> from `stdin', one line at a time. *You could then examine the data
> for the current line in your loop, and make a decision as to what you
> want to do.
>
> Just a bit of a disclaimer, I'm still in the process of learning C as
> well.


nevertheless you were correct
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-02-2009
(E-Mail Removed) writes:

> On 1 Mar, 23:07, raeiko <(E-Mail Removed)> wrote:
>
>> i urgently need your help

>
>
>
>> I have to write a C program that reads a series of strings and prints
>> only those that end with the letters “ed.” To enter the string i
>> should use the command line prompt and when i press the return key,
>> the program should print the string if it ends in "ed" and prompt for
>> another string if it doesn't.

>
> I think other posters have seriously misunderstood you.
> This is plainly an interactive program (no command line arguments
> needed)


One other poster.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start java GUI program WITHOUT additional Windows command line prompt console window? Ulf Meinhardt Java 1 08-10-2009 06:32 AM
javac command not working in command prompt chrisdude911 Java 10 03-10-2009 09:55 AM
Re: c program - command line prompt - need help jacob navia C Programming 29 03-05-2009 02:16 AM
Command line prompt broken on XP with Python 2.5 - help! Endless Story Python 9 02-16-2007 05:24 PM
Access Denied when i type command at command prompt calvin MCDST 0 03-08-2006 06:33 AM



Advertisments