从C中输入文件扫描,直到达到一定的字符(#)? [英] scanning from an input file in C until reaching a certain character (#)?
问题描述
简单问题:
如果我有,看起来很像输入文件中的一行:
If i have a line in an input file that looks looks like:
Hello#Great#Day#Today
我怎么能在每一个字扫描单独作为自己的阵列,换句话说告诉C当它到达#字符以停止扫描,然后在循环的下一次迭代去扫描下一个字作为一个单独的数组?
how can I scan in each word individually as its own array, in other words tell C to stop scanning when it reaches the # character and then go in the next iteration of the loop to scan the next word as a separate array?
推荐答案
这是假设你是通过标准输入
读书。绝对看一看@Whoz踢启动的方法,以及(非常类似于这样)。
This is assuming you are reading through stdin
. Definitely take a look at @Whoz kick start approach as well (very similar to this).
你所想要做的就是创建一个动态数组,并通过标准输入
每读取一个字节填充它。那么你想创建字符指针数组,将指向第一个字符在每一个字,在这里你定义一个字像以前一样每一个字符一个'#'
字符(分隔符)。然后,您将通过字符数组迭代,并填充每个单词的第一个字符的内存地址字符指针数组。
What you would want to do is create a dynamic array and populate it with every byte read through stdin
. You would then want to create an array of character pointers that will point to the first character in every "word", where you define a word as every character before a '#'
character (delimiter). You would then iterate through that array of characters and populate the array of character pointers with the memory addresses of the first character in each word.
这篇关于从C中输入文件扫描,直到达到一定的字符(#)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!