我正在使用fopen来确定我是打开文件还是像这样的目录:
FILE *f;
f = fopen(path, "r");
if (f != NULL){
// found file
}
else {
// found a directory
}
Run Code Online (Sandbox Code Playgroud)
而path当前是指向目录的路径,而不是文件,它看起来像这样:
/home/me/Desktop/newfolder
Run Code Online (Sandbox Code Playgroud)
但是,当我运行代码时,它说它找到了一个文件,即使它指向一个文件夹,因此它应该返回NULL指针,或不?
我正在研究Ubuntu.
我正在尝试通过以下循环创建一个包含人员及其孩子姓名的 XML 文件:
$xml_file = new XMLWriter();
$xml_file->startElement("People");
while ($list_of_people->current != NULL ){
$xml_file->writeElement("Person"); // create a new person
$xml_file->startElement('Person');
$xml_file->writeAttribute('name', $list_of_people->current->name); // add their name as an attribute
if ($list_of_people->current->children != NULL){
while ($list_of_people->current->child_current != NULL){ // if they have children create them as well
$xml_file->writeElement("Person");
$list_of_people->startElement('Person');
$xml_file->writeAttribute('name', $list_of_people->current->child_current->child_name);
$xml_file->endElement();
$list_of_people->current->child_current = $list_of_people->current->child_current->next;
}
}
$xml_file->endElement();
$list_of_people->current = $list_of_people->current->next;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,在输出文件中,我应该有多个名为“Person”的元素,具体取决于列表中有多少人以及其中有多少人有孩子。
我希望最终的 XML 文档看起来像这样:
<People>
<Person name="Anna"></Person>
<Person name="Joe">
<Person name="Willy"></Person> // Joe has a child named Willy
</Person> …
Run Code Online (Sandbox Code Playgroud) 我无法想出一个表达式,它会在最后一次斜杠后让我获得字符串的一部分.
让我说我有 argv[1] = "HIsomething:01/02/03.file";
如何让sscanf只存储最后一次斜线后写的内容?(本例中为"03.file")?斜杠的数量不固定.
我知道如果我写的话
char string [100];
sscanf(argv[1], "HIsomething:%99[^\n]", string);
Run Code Online (Sandbox Code Playgroud)
我可能会将"01/02/03.file"存储在字符串中.
我不能只是手动输入它,因为参数可能不同,我需要一个通用的解决方案,只需在最后一次斜线后获取所有内容.
假设我在 AX 中存储了以下值:1000100001001,在 CL 中我的值为 1。
当我执行 ROL AX, CL 指令时,我的 SW 告诉我 AX 的内容现在是 10001000010010。
然而,正确答案不应该是 00010000100101 吗?(我将所有位都向左滚动,因此 MSB 在右侧作为 LSB 出现?)
我正在寻找一个正则表达式,它还可以识别和分隔逗号,等号以及输入中可能需要的任何其他特殊字符.
现在我拥有的是什么 $content = preg_split('/[\s]+/', $file_content, -1, PREG_SPLIT_NO_EMPTY);
它将输入文件的内容存储到一个数组中,其中每个元素由空格分隔.
但是例如对于function a (int i) {};
数组看起来像这样:
[0] = function
[1] = a
[2] = (int
[3] = i)
[4] = {};
Run Code Online (Sandbox Code Playgroud)
我想用正则表达式实现的目的是:
[0] = function
[1] = a
[2] = (
[3] = int
[4] = i
[5] = )
[6] = {
[7] = }
[8] = ;
Run Code Online (Sandbox Code Playgroud)
我一直在网上搜索一段时间,无法真正找到我需要的东西.提前致谢!
我需要对using
有关类的关键字进行快速说明,因为我不确定我是否正确理解。
假设我有以下示例:
class B {
public:
int var;
int f(void);
};
class C : public B {protected: using B::var; };
Run Code Online (Sandbox Code Playgroud)
这是否意味着,而不是继承的变量var
如public
从B类,C类,而不是继承此变量protected
,离开将是唯一的公共变量int f(void);
?
另外,类C是否可以通过private: using B::var;
在其主体内部继承而将变量作为私有变量继承?
public: using B::var;
既然变量var已经在B类内部公开了,那有什么写法吗?
谢谢!
可以使用与此类似的方法完成此操作:
只要用户通过scanf输入的字符串的当前元素不是\ 0,将一个添加到"length"int,然后打印出长度.
如果有人能够以最简单的方式指导我,我会非常感激,因为我是初学者.
非常感谢,有一个好的!
我有多年的问题mktime()
.
每次我将一年低于1970年的时间传递给我struct tm
,然后运行mktime()
转换我的结构的函数,它就会失败(返回-1).
有谁知道为什么以及我能以某种方式完成这项工作?