Knighthana
文章96
标签139
分类7

文章归档

Take Space Key In Scanf

Take Space Key In Scanf

Take Space Key In Scanf


How to colorful a C text in linux shell?

1
printf("\033[0;32;40m%s\033[0m$",pwd(user));

used in my code.

1
\033[0;32;40m

means ordinary text, green text, black background.

1
\033[0m

means change back to default settings.

How to take a space key while using scanf?

1
scanf("%[^\n]",buf);

means that get input until a '', and save it into buf.

1
scanf("%[^\n]%*c",buf);

means that get input until a '', and save it into buf, then drop next character('').(I will use in my function).

1
scanf("%*[^\n]%*c");

means thet get input until a '', and drop it, then get a character(''), drop it too.

1
scanf("%*[^a]%*c%c",&ch);

means that get input until a 'a', and drop it, then get a character( 'a'), drop it too. After that, get a character and save it into ch.

input:

bcdeaf

output:

f

Refer: scanf读取含空格的字符串

Knighthana@XDU

2019/6/6