Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > scanf right square bracket

Reply
Thread Tools

scanf right square bracket

 
 
prodziedzic@gmail.com
Guest
Posts: n/a
 
      05-04-2007
I want use scanf to read from input everything till right square
bracket ']'.

It seems to be something like that:
scanf("%[^\]]) but that's not working.

Any ideas?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I want use scanf to read from input everything till right square
> bracket ']'.
>
> It seems to be something like that:
> scanf("%[^\]]) but that's not working.
>
> Any ideas?


A couple. First, 'comp.lang.c' is a [marginally] better place
to ask about the functionality of C standard library functions.
Second, have you tried using 'getline' and parse the input line
yourself? 'string' has plenty of functionality to locate your ']'
and trim the input. Third, the C standard says that the right
bracket has to be the first in your sequence to be considered in
it, IOW, the sequence has to be "%[^]]" if you want to read any
character up to the bracket.

#include <cstdio>
int main()
{
char c[10] = {}, s[] = "123]321";
int i = sscanf(s, "%[^]]", c);
printf("scanned %d fields, c = <%s>\n", i, c);
}

Should print
scanned 1 fields, c = <123>

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
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
Square bracket and dot notations? Asen Bozhilov Python 4 06-11-2011 07:49 PM
can't use "glog" to find the path with square bracket winterTTr Python 2 04-29-2009 01:20 AM
Square bracket possible in href of xsl:result-document? skippyd277@yahoo.com XML 1 03-14-2008 08:24 AM
XPath: Using the outside context inside a square bracket predicate Wabiloo XML 1 01-25-2008 04:38 PM
Missing right curly or square bracket (but that isnt the case) daveyand Perl Misc 4 05-24-2006 03:57 PM



Advertisments