Skip remainder of line with fscanf in C

前端 未结 3 1737
暖寄归人
暖寄归人 2021-01-06 13:31

I\'m reading in a file and after reading in a number, I want to skip to remaining part of that line. An example of a file is this

2 This part should be skipp         


        
3条回答
  •  花落未央
    2021-01-06 14:00

    I wanted to parse the /proc/self/maps file, but only wanted the first 2 columns (start and end of address range). This worked fine with Linux gcc.

    scanf("%llx-%llx %*[^\n]\n", &i, &e);

    The trick was "%*[^\n]\n" which means skip a sequence of anything except the end of line, then skip the end of line.

提交回复
热议问题