我试图通过重新设计我在学期中从用C语言编写的DB类(创建自己的数据库系统)中完成的项目的API来理解C和C++之间的区别.现在我正在尝试重新设计项目的API,它也可以在用C++语言编写的应用程序中使用.
我有混淆typedef struct,enum,float等.
我用C头文件中的代码如下所示:
typedef enum { FALSE = 0, TRUE } bool_t;
typedef float real;
...
typedef struct _hf_record_identification {
int pagenum;
int recnum;
} RECID;
Run Code Online (Sandbox Code Playgroud)
在阅读了一些关于它的引用之后,我得出结论,它可以用C++表示,如:
enum bool_t {FALSE = 0, TRUE };
float real;
...
struct _hf_record_identification RECID {
int pagenum;
int recnum;
} ;
Run Code Online (Sandbox Code Playgroud)
我的问题是:typedefC和typedefC++ 之间的主要区别是什么?typedef对我来说,在C++中使用起来并不方便.我把它与C混淆了.我是否正确地做了typedef float real案例?
我正在阅读C中的循环,我发现了一行有趣的代码,我无法理解.如果有人能解释我这行,我将不胜感激:
for (; count>0; count--, j++)
但整个代码是这样的:
while(getline(&line, &count, input) != -1)
{
for ( ; count>0; count--, j++)
sscanf(line, "%d", &array[i]);
i++;
}
Run Code Online (Sandbox Code Playgroud)
变量count是size_t类型,int i,j = 0 以及FILE *input;用于读取存储在文本文件中的数字序列.
提前致谢.