Scanset behaviour in scanf in C

前端 未结 2 1520
青春惊慌失措
青春惊慌失措 2021-02-04 18:40

I tried to do some stuff with scanset in scanf but stuck somewhere.

when I write

char s1[250];
scanf(\"%[A-Z]\",s1);

input : AHJHkiuy
Output: AHJH


        
相关标签:
2条回答
  • 2021-02-04 19:19

    You could expand your example a little bit and achieve your goal.

    scanf("%[A-Za-z ]", s1);
    
    0 讨论(0)
  • 2021-02-04 19:26

    Another way to do this would be:

    scanf("%[^0-9]", s1); /* Scans everything until a digit */
    
    0 讨论(0)
提交回复
热议问题