vendredi 31 juillet 2015

How does scanf function work in this program?

Can anyone please explain how this scanf function works? What does the [a] in %[a]s do? If an input aabbab is given, it prints aa and 2. But if it is changed to %[b]s, then it prints 12.exe and 6.

#include<stdio.h>
#include<string.h>


int main()
{
    char str[10];
    scanf("%[a]s",&str);
    printf("%s\t %d",str,strlen(str));
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire