sscanf assignment suppression character 
Author Message
 sscanf assignment suppression character



Quote:
> I came across a function the other day which uses the assignment
> suppression character * in conjunction with sscanf. The relevant lines
> of code are pasted below. Can someone explain to me what the author of
> the program may be up to? What is the point of having _four_
> conversion
> specifications in the format string, when there are only _three_ input
> items?
> Apparently the suppression character will ignore one of the four
> conversion
> specifications, but what is the point of that? What am I missing here?

<snip>

Quote:
>     sscanf(buf, "%s %*d %d %c", s, &low, &flags);

It's quite simple really. The string contains four data, but on this
particular occasion the programmer is only interested in three. So this
statement means roughly:

Using buf as your data source, give me a string, stick it in s. Then comes
an int that I couldn't give two hoots about, so just throw it away. THEN
comes an int I DO want, so stick it in low. Then there's a char to put in
flags.

HTH

--
Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.



Sun, 03 Mar 2002 03:00:00 GMT  
 sscanf assignment suppression character


Quote:
> I came across a function the other day which uses the assignment
> suppression character * in conjunction with sscanf. The relevant lines
> of code are pasted below. Can someone explain to me what the author of
> the program may be up to? What is the point of having _four_
> conversion
> specifications in the format string, when there are only _three_ input
> items?
> Apparently the suppression character will ignore one of the four
> conversion
> specifications, but what is the point of that? What am I missing here?

A paltry example of where this could be useful:

-----------------

#include <stdlib.h>
#include <stdio.h>

int main() {
    int hours, mins;
    char t[] = "11:15am";

    sscanf(t, "%d%*c%d", &hours, &mins);

    printf("Hours is %d, mins is %d\n", hours, mins);

    return EXIT_SUCCESS;

Quote:
}

--------------

Regards
Paul



Sun, 03 Mar 2002 03:00:00 GMT  
 sscanf assignment suppression character
You are missing the point. There are four items to be converted from the
input, but the author wants to discard one of them. The unimportant item
needs to be dealt with, so the items beyond it can be reached by the
converter.

char *input = "12 -1 13 14"; /* just want 3 of them */

int a,b,c;

sscanf(input,"%d %*d %d %d",&a,&b,&c);

--

Paul Lutus
www.arachnoid.com


Quote:
> I came across a function the other day which uses the assignment
> suppression character * in conjunction with sscanf. The relevant lines
> of code are pasted below. Can someone explain to me what the author of
> the program may be up to? What is the point of having _four_
> conversion
> specifications in the format string, when there are only _three_ input
> items?
> Apparently the suppression character will ignore one of the four
> conversion
> specifications, but what is the point of that? What am I missing here?

> Thanks,

> David King.

> /* add a group to a newsgroups list, buf is list active output */
> void addgroup(struct newsgroups **first, char *buf)
> {
>     struct newsgroups *this, *last=NULL;
>     char s[4096];
>     int low;
>     char flags;

>     sscanf(buf, "%s %*d %d %c", s, &low, &flags);



Sun, 03 Mar 2002 03:00:00 GMT  
 sscanf assignment suppression character
I came across a function the other day which uses the assignment
suppression character * in conjunction with sscanf. The relevant lines
of code are pasted below. Can someone explain to me what the author of
the program may be up to? What is the point of having _four_
conversion
specifications in the format string, when there are only _three_ input
items?
Apparently the suppression character will ignore one of the four
conversion
specifications, but what is the point of that? What am I missing here?

Thanks,

David King.

/* add a group to a newsgroups list, buf is list active output */
void addgroup(struct newsgroups **first, char *buf)
{
    struct newsgroups *this, *last=NULL;
    char s[4096];
    int low;
    char flags;

    sscanf(buf, "%s %*d %d %c", s, &low, &flags);



Mon, 04 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. "scanf" function with assignment-suppression

2. file i/o -- assignment suppression

3. sscanf and characters

4. Character assignment causes bus error

5. Windows Application Error Suppression?

6. HELP: Alignment suppression in C/UNIX

7. DocTemplate suppression

8. Suppression d'un DocTemplate

9. warning: ambiguous assignment: assignment op taken

10. multi-character character constant

11. Support for characters not in default character set?

12. Delete each character in s1 that matches any character in s2

 

 
Powered by phpBB® Forum Software