Unix Programming - scanf()

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > scanf()





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author scanf()
John

2005-05-25, 6:02 pm

can somebody provide me with a scanf that can scan upto but not
including a specific character.

For example: I would like to caputure all characters before the '-'.

My data can look like this.

"123 - "
"123-"
"ABCDE -"
"A1BCD-"
.....
.....

In each case I want to skip all white space proceeding the '-' and the
'-' itself.

Thanks in advance for all that answer this post.

Alan Balmer

2005-05-25, 6:02 pm

On 25 May 2005 14:01:04 -0700, "John" <sirsquatalot405@hotmail.com>
wrote:

>can somebody provide me with a scanf that can scan upto but not
>including a specific character.
>
>For example: I would like to caputure all characters before the '-'.
>
>My data can look like this.
>
>"123 - "
>"123-"
>"ABCDE -"
>"A1BCD-"
>....
>....
>
>In each case I want to skip all white space proceeding the '-' and the
>'-' itself.
>
>Thanks in advance for all that answer this post.


Is this homework? Give it a try. Post your code here, and you'll get
comments.

--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net
Paul Pluzhnikov

2005-05-25, 8:53 pm

"John" <sirsquatalot405@hotmail.com> writes:

> can somebody provide me with a scanf that can scan upto but not
> including a specific character.


Try "man scanf", and look for '%[' conversion.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Stu

2005-05-26, 8:06 am

Try this.

char *p="ABCEFG -123";
char var[20];

sscanf (p, "%[^ -]",var);

Note the space after the circumflex plus the size of var should be
large enough to hold your result

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com