In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what is the role of% * s in C language", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this article "what is the role of% * s in C language".
Depends on whether it is used in scanf or printf.
When used in scanf, the part with * added will be ignored and will not be obtained by parameters. For example:
Int a dint btterchar b [10]; scanf ("% d% s", & a memo b)
The input is: 12 abc, then 12 will be read into the variable a, but the subsequent abc will be discarded after reading and will not be assigned any variables (for example, the character array b here)
Used in printf to represent the position replaced by the following parameters to achieve dynamic format output. For example:
Printf ("% s", 10, s); / means to output the string s, but occupy at least 10 positions, and fill in the blanks to the left of the string s, which is equivalent to printf ("s", s); * /
For example, if you want to print the first line "Name: login" in / proc/x/status under the linux root file system, as follows
[root@sz / proc/898] # cat status Name: loginState: s (sleeping) Tgid: 898Pid: 898PPid: 519TracerPid: 0Uid: 000 0Gid: 000 0FDSize: 32Groups:VmPeak: 1232 kBVmSize: 1232 kBVmLck: 0 kBVmPin: 0 kBVmHWM: 312 kBVmRSS: 312 kBVmData: 64 kBVmStk: 136 kBVmExe: 708 kBVmLib: 312 kBVmPTE: 8 kBVmSwap: 0 kBThreads: 1SigQ: 0/469SigPnd: 0000000000000000ShdPnd: 0000000000000000SigBlk: 0000000000000000SigIgn: 0000000000000000SigCgt: 0000000000002000CapInh: 0000000000000000CapPrm: 0000001fffffffffCapEff: 0000001fffffffffCapBnd: 0000001fffffffffCpus_allowed: 1Cpus_allowed_list: 0Mems_allowed: 1Mems_allowed_list: 0voluntary_ctxt_switches: 1nonvoluntary_ctxt_switches: 2
To get only the login in "Name: login", you can use the following
/ / description: whether the thread exists / / return: successful indicates existence, returns true, and vice versa is false. Bool IsThreadExist (char * task_name) {DIR * dir; struct dirent * ptr; FILE * fp; char filepath [50]; char cur_task_name [50]; char buf [BUF _ SIZE]; bool fRet = false; dir = opendir ("/ proc") If (NULL! = dir) {while ((ptr = readdir (dir))! = NULL) {if ((strcmp (ptr- > d_name, ".) = = 0) | (strcmp (ptr- > d_name,".. ") = 0) continue; if (DT_DIR! = ptr- > d_type) continue Sprintf (filepath, "/ proc/%s/status", ptr- > d_name); fp = fopen (filepath, "r"); if (NULL! = fp) {if (fgets (buf, BUF_SIZE-1, fp) = = NULL) {fclose (fp); continue } sscanf (buf, "% * s% s", cur_task_name); if (strcmp (task_name, cur_task_name) = = 0) {fRet = true;} fclose (fp);}} closedir (dir) } return fRet;} above is the content of this article on "what is the role of% * s in C language". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.