- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一项阅读一本书的家庭作业。首先,读入一行并使指针指向该行。然后一个段落函数读取行并将它们的地址存储到一个指针数组中。现在,我正在阅读一章(下一行被打破的段落)。它应该调用 get_paragraph()
并存储段落的地址,直到到达新的章节。
新章节是书中唯一一次第一个字符不是空格的情况。我认为这是我的代码有问题。到目前为止的所有功能都可以工作。我希望我已经提供了足够的信息。代码编译但启动时核心转储。
我是一名学生,正在学习,所以请善待。谢谢。
char*** get_chapter(FILE * infile){
int i=0;
char **chapter[10000];//an array of pointers
// Populate the array
while(chapter[i]=get_paragraph(infile)) { //get address store into array
if(!isspace(**chapter[0])){ //check to see if it is a new chapter<---problem line?
// save paragraph not used in chapter using static to put into next chapter
break;
}
i++;//increment array
}
//add the null
chapter[++i]='\0';//put a null at the end to signify end of array
//Malloc the pointer
char**(*chap) = malloc(i * sizeof(*chap));//malloc space
//Copy the array to the pointer
i=0;//reset address
while(chapter[i]){//while there are addresses in chapter
chap[i] = chapter[i++];//change addresses into chap
}
chap[i]='\0';//null to signify end of chapter
//Return the pointer
return(chap);//return pointer to array
}
对于那些宁愿看到没有评论的人:
char*** get_chapter(FILE * infile){
int i=0;
char **chapter[10000];
while(chapter[i]=get_paragraph(infile)) {
if(!isspace(**chapter[0])){
break;
}
i++;
}
chapter[++i]='\0';
char**(*chap) = malloc(i * sizeof(*chap));//malloc space
i=0;
while(chapter[i]){
chap[i] = chapter[i++];
}
chap[i]='\0';
return(chap);
}
最佳答案
内联评论。
char*** get_chapter(FILE * infile) {
int i=0;
// This is a zero length array!
// (The comma operator returns its right-hand value.)
// Trying to modify any element here can cause havoc.
char **chapter[10,000];
while(chapter[i]=get_paragraph(infile)) {
// Do I read this right? I translate it as "if the first character of
// the first line of the first paragraph is not whitespace, we're done."
// Not the paragraph just read in -- the first paragraph. So this will exit
// immediately or else loop forever and walk off the end of the array
// of paragraphs. I think you mean **chapter[i] here.
if(!isspace(**chapter[0])){
break;
}
i++;
}
// Using pre-increment here means you leave one item in the array uninitialized
// which can also cause a fault later on. Use post-increment instead.
// Also '\0' here is the wrong sort of zero; I think you need NULL instead.
chapter[++i]='\0';
char**(*chap) = malloc(i * sizeof(*chap));
i=0;
while(chapter[i]) {
// This statement looks ambiguous to me. Referencing a variable twice and
// incrementing it in the same statement? You may end up with an off-by-one error.
chap[i] = chapter[i++];
}
// Wrong flavor of zero again.
chap[i]='\0';
return(chap);
}
关于解析章节时的Coredump,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4151917/
我想预加载同一视频的各个章节。这样当有人跳到新章节时就不会出现缓冲。 例如,如果第一章从 00:00 开始,下一章从 00:15 开始,我希望我的播放器提前预加载每章 2-3 秒。 最佳答案 您可以尝
我似乎无法在 NASM 的文档中找到任何关于在代码中使用“Section”或“[SECTION”(带方括号)之间的区别的明确信息。我知道这些是宏,但我发现它们几乎可以互换使用。是这样吗?换句话说就是
最近我去了w3schools New HTML5 Elements并发现了“section”和“article”标签。我的问题是什么时候应该使用节、文章或 div 标签,为什么当我使用节和文章标签时文
我正在尝试使用 JavaScript 来导航 Quicktime 视频中的章节。 我可以使用此功能查看每个 Quicktime 有多少章: function GetChapterCount(an
Eloquent javscript 在模块章节的第 10 章中写道: The most obvious way is the special operator eval, which will ex
我正在开发 HTML5 应用程序,我在其中使用了以下标签。 我想知道在 HTML5 应用程序中这些标签的实际用途是什么。我们已经使用了 我们传统应用程序中的标签也与上面给定的标签一样工作,所以
我正在尝试使用适用于 Linux 的 WKHTMLTOPDF 生成一本 PDF 书籍,并通过 Perl 程序享用午餐。我将多个带有封面和页脚信息的 html 文件通过 html 文件传递到 WKH
在关于流的介绍性章节中,Okasaki 为 drop 提供了 2 个实现。在溪流上。 他明确提到第二个更有效(并且两者具有相同的语义),但我似乎无法弄清楚为什么一个比另一个更有效。任何见解将不胜感激。
什么是 rails 方式显示嵌套层次结构的 View ?似乎是一个简单的问题,但试着忍受我,也许有人会理解(并希望能消除)我的困惑。 我的应用程序是一个简单的层次结构(为了讨论的目的而更加简化): 在
我是一名优秀的程序员,十分优秀!