我想编写一个函数,它获取指向链表头的指针,并从列表中删除每个第二个成员.List是type 元素的链接元素:
typedef struct element{
int num;
struct element* next;
}element;
Run Code Online (Sandbox Code Playgroud)
我是所有这些指针算法的新手,所以我不确定我是否正确写入:
void deletdscnds(element* head) {
element* curr;
head=head->next; //Skipping the dummy head//
while (head!=NULL) {
if (head->next==NULL)
return;
else {
curr=head;
head=head->next->next; //worst case I'll reach NULL and not a next of a null//
curr->next=head;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不断改变它,因为我一直在发现错误.你能指出任何可能的错误吗?
我正在使用C,我想从二进制文件中读取.
我知道它以下列方式包含字符串:字符串的长度,字符串本身,字符串的长度,字符串本身等等......
我想计算字符串Str出现在二进制文件中的次数.
所以我想做这样的事情:
int N;
while (!feof(file)){
if (fread(&N, sizeof(int), 1, file)==1)
...
Run Code Online (Sandbox Code Playgroud)
现在我需要获取字符串本身.我知道它的长度.我应该做一个'for'循环并通过char获取fgetc char吗?我知道我不允许使用fscanf,因为它不是文本文件,但我可以使用fgetc吗?我能得到我期待的弦乐吗?(要使用长度大小为char*使用动态分配,并使用strcpy将其添加到当前字符串?)