Olufowobi Lawal wrote:
>
>
>
> I don't know about you , but it works with me.
>
> input sth like.
> abc/n
> and you'll get
> abc/
>
> Maybe you should make clear what you are trying to achieve.
>
> You could Read this up too
> http://linux.die.net/man/3/scanf <http://linux.die.net/man/3/scanf>
> [
> Matches a nonempty sequence of characters from the specified set of
> accepted characters; the next pointer must be a pointer to char,
> and there must
> be enough room for all the characters in the string, plus a terminating
> null byte. The usual skip of leading white space is suppressed. The
> string is to be
> made up of characters in (or not in) a particular set; the set is
> defined by the characters between the open bracket [ character and a
> close bracket ] character. The set excludes those characters if the
> first character after the open bracket is a circumflex (^).
> To include a close
> bracket in the set, make it the first character after the open bracket
> or the circumflex; any other position will end the set. The hyphen
> character - is also special; when placed between two other characters, it
> adds all intervening characters to the set. To include a hyphen, make
> it the last
> character before the final close bracket. For instance, [^]0-9-] means
> the set "everything except close bracket, zero through nine, and
> hyphen". The string ends with the appearance of a character not in the
> (or, with a circumflex, in) set or when the field width runs out.
>
> Lawal.O
>
> ________________________________
> From: ayyaz <[email protected] <mailto:ayyaz84%40gmail.com>>
> To: [email protected] <mailto:c-prog%40yahoogroups.com>
> Sent: Sunday, June 21, 2009 9:31:51 PM
> Subject: [c-prog] Why doesn't this work?
>
> Hello,
>
> Why doesn't the following code work?
>
> #include <stdio.h>
>
> int main(void)
> {
> char text[80];
>
> printf("Please enter a text: ");
> scanf("%[\^n] ",text);
> printf("\n%s" ,text);
>
> }
>
> Thanks,
> --ayyaz
>
> [Non-text portions of this message have been removed]
>
>
Hello,
There was a typo in my code because of which it wasn't working.
scanf("%[\^n] ",text); should be scanf("%[^\n] ",text);
The carrot tells it take everything except a new line. The backslash
goes after the carrot.
The purpose of the program was to take some text and store it in
variable text and then display it.
Thanks,
--ayyaz