因此,我有一项任务,即Im应该用读写读写,从档案中读写,然后用文字写。 然而,我不能让它工作。
I have to call a sort function on buf first to sort the string (which I got using read) before I re-output it. Can I treat buf as an array? Or does it not work like that? The reason is because I have to sort the string first.
int record_compare(const void *a, const void *b)
{
return (memcmp(a, b, num_bytes));
}
qsort(buf, num_elements, num_bytes, record_compare);
while (count < n - num_bytes)
{
i = memcmp(buf+count, buf+count + num_bytes, num_bytes);
if (i == 0)
count = count + num_bytes;
else
{
for (k = 0; k < num_bytes; k++)
{
printf("%c", buf[count]);
count++;
}
}
}
但是,由于我看上去,而不是像植被这样的东西,我仍然能够把香料当作一个阵列? 这就是这种类型如何在普通阵列上发挥作用(然后在不重复的情况下加以打印)。
do {
c = read(0, buf+n, 1);
if (c != 0)
n++;
}
while (c != 0);
这就是我如何做。