I have:
#define MAX_STR_LEN 100
and I want to put into scanf
pattern so I can control the string length:
scanf("%100[^
]s",sometext)
I tried:
scanf("%MAX_STR_LEN[^
]s",sometext)
scanf("%"MAX_STR_LEN"[^
]s",sometext)
scanf("%",MAX_STR_LEN,"[^
]s",sometext)
And it didn't work. I just want to avoid buffer overflow since "sometext" is allocated with malloc(MAX_STR_LEN)
...
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…