Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 188157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:57:19+00:00 2026-05-11T15:57:19+00:00

I have run into some code and was wondering what the original developer was

  • 0

I have run into some code and was wondering what the original developer was up to. Below is a simplified program using this pattern:

      #include <stdio.h>        int main()  {             char title[80] = 'mytitle';             char title2[80] = 'mayataiatale';             char mystring[80];         /* hugh ? */       sscanf(title,'%[^a]',mystring);       printf('%s\n',mystring); /* Output is 'mytitle' */         /* hugh ? */       sscanf(title2,'%[^a]',mystring); /* Output is 'm' */       printf('%s\n',mystring);         return 0;     } 

The man page for scanf has relevant information, but I’m having trouble reading it. What is the purpose of using this sort of notation? What is it trying to accomplish?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:57:20+00:00Added an answer on May 11, 2026 at 3:57 pm

    The main reason for the character classes is so that the %s notation stops at the first white space character, even if you specify field lengths, and you quite often don’t want it to. In that case, the character class notation can be extremely helpful.

    Consider this code to read a line of up to 10 characters, discarding any excess, but keeping spaces:

    #include <ctype.h> #include <stdio.h>  int main(void) {     char buffer[10+1] = '';     int rc;     while ((rc = scanf('%10[^\n]%*[^\n]', buffer)) >= 0)     {             int c = getchar();             printf('rc = %d\n', rc);             if (rc >= 0)                     printf('buffer = <<%s>>\n', buffer);             buffer[0] = '\0';     }     printf('rc = %d\n', rc);     return(0); } 

    This was actually example code for a discussion on comp.lang.c.moderated (circa June 2004) related to getline() variants.


    At least some confusion reigns. The first format specifier, %10[^\n], reads up to 10 non-newline characters and they are assigned to buffer, along with a trailing null. The second format specifier, %*[^\n] contains the assignment suppression character (*) and reads zero or more remaining non-newline characters from the input. When the scanf() function completes, the input is pointing at the next newline character. The body of the loop reads and prints that character, so that when the loop restarts, the input is looking at the start of the next line. The process then repeats. If the line is shorter than 10 characters, then those characters are copied to buffer, and the ‘zero or more non-newlines’ format processes zero non-newlines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I basically handle this in one of two ways. 1)… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer You need to call reset_column_information on the model you changed… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer Since interfaces in C# cannot contain definitions for operators (or… May 11, 2026 at 7:46 pm

Related Questions

Where I work, the design and development departments are totally separated, however we (the
I was reading this question to find out the differences between the Java Virtual
In a Flash game I am developing, there are some settings that are set
The first real software company that I worked at was all about the unit
I've attempted to create an abstracted control to manage some of the state in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.