Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Reading inp...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 22 of 25 Topic 26096 of 26972
Post > Topic >>

Re: Reading input problem

by arnuld <sunrise@[EMAIL PROTECTED] > May 10, 2008 at 12:08 AM

> On Thu, 08 May 2008 11:54:31 +0100, Ben Bacarisse wrote:


> I doubt anyone will write this for you.  It is a rather specific input
> routine and you will just have to work out a way to do it yourself.
> Do you plan using pseudo-code before starting to write the C?  You
> will need to, I think, because such an input routine is quite
> complex.

yes, it is complex *only* in C, I guess:

I can discard the words containing anything else than characters:


/* version 1.4 */

int getword( char *word, int max )
{
  int c, in_word;
  char *w, *w_begin;

  w_begin = word;
  w = word;
  in_word = 0;

  while( isspace( c = getchar() ))
    {
      continue;
    }


  if( isalpha( c ))
    {
      *w++ = c;
    }

  for( ; ( (c = getchar()) != EOF ) && --max ; ++w )
    {
      if( isalpha(c) )
	{
	  in_word = 1;
	  *w = c;
	}
      else if( c == EOF || isspace( c ) )
	{
	  *w = '\0';
	  in_word = 0;
	  return 1;
	}
      else
	{ 
	  if( in_word )
	    {
	      while( w != w_begin )
		{
		  *w-- = '\b';
		}
	      *w-- = '\b';
	    }
	}
    }



  *w = '\0';

  return word[0];
}
============= OUTPUT ==============
[arnuld@[EMAIL PROTECTED]
 C]$ gcc -ansi -pedantic -Wall -Wextra getword.c
[arnuld@[EMAIL PROTECTED]
 C]$ ./a.out 
Ben9
---------->  
9Ben
---------->  Ben
Be9n
---------->  n
[arnuld@[EMAIL PROTECTED]
 C]$ 



now only 2 things have remained:

1.) it does not discard the whole-word if the non-character comes as 1st
element or within the word like 9Ben or Be9n but it will discard Ben9
completely. So it is juts a half-implementation yet.


2.) as usual, does not discard characters more than 30 .   


any ideas on that ?



-- 
http://lispmachine.wordpress.com/
my email ID is @[EMAIL PROTECTED]
 the above blog.
just check the "About Myself" page :)
 




 25 Posts in Topic:
Reading input problem
arnuld <sunrise@[EMAIL  2008-05-07 11:30:57 
Re: Reading input problem
Ben Bacarisse <ben.use  2008-05-07 10:58:41 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-09 02:37:42 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-08 10:41:14 
Re: Reading input problem
CBFalconer <cbfalconer  2008-05-07 12:35:35 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-09 02:35:14 
Re: Reading input problem
CBFalconer <cbfalconer  2008-05-08 13:57:23 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-09 02:36:41 
Re: Reading input problem
Ian Collins <ian-news@  2008-05-08 17:00:03 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-08 10:39:36 
Re: Reading input problem
Ian Collins <ian-news@  2008-05-08 18:15:26 
Re: Reading input problem
Richard Heathfield <rj  2008-05-08 07:14:08 
Re: Reading input problem
Ian Collins <ian-news@  2008-05-08 17:03:05 
Re: Reading input problem
CBFalconer <cbfalconer  2008-05-08 13:59:58 
Re: Reading input problem
pete <pfiland@[EMAIL P  2008-05-08 05:24:35 
Re: Reading input problem
Ben Bacarisse <ben.use  2008-05-08 11:45:24 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-09 20:36:41 
Re: Reading input problem
jacob navia <jacob@[EM  2008-05-09 10:20:33 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-10 07:11:22 
Re: Reading input problem
jacob navia <jacob@[EM  2008-05-09 13:33:45 
Re: Reading input problem
Ben Bacarisse <ben.use  2008-05-08 11:54:31 
Re: Reading input problem
arnuld <sunrise@[EMAIL  2008-05-10 00:08:14 
Re: Reading input problem
Barry Schwarz <schwarz  2008-05-09 10:55:56 
Re: Reading input problem
Antoninus Twink <nospa  2008-05-09 13:50:58 
Re: Reading input problem
Eligiusz Narutowicz<el  2008-05-09 14:04:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:28:05 CDT 2008.