我试图读取文本文件中的条目并将其放入类中.文本文件的结构如下:
ABCD
3.00
2
6.00
-
Run Code Online (Sandbox Code Playgroud)
进入一个班级:
typedef struct item
{
char *name;
double uprc;
double cost;
int qty;
} item;
Run Code Online (Sandbox Code Playgroud)
"ABCD"是名称,3.00是uprc,2是qty和6.00 cost.
我该如何实现呢?到目前为止,我有:
void read()
{
item i;
FILE *f = fopen(PATH, "r");
char *buf;
int c, nl_ct = 0;
while((c = getch(f)) != EOF){
putchar(c);
if(c == '\n'){
nl_ct++;
switch(nl_ct){
case 1:
{
char *buf;
while(fgets(buf, sizeof(buf), f))
}
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我不知道在最里面的while循环中该做什么.此外,此代码看起来不正确.
我该如何编码呢?
我的程序经常调用WINAPI函数timeGetTime(),应该替换为<chrono>(标准库)的使用.什么是最快的标准化的方式来获取系统时间-在float或int,我的情况?
我不需要跟踪日期或日期时间,我只需要精确的相对ms /秒值,它总是递增.有没有?
如果用记事本打开*.gif文件,文件将以GIF89开头
但是对于*.jpeg文件,第一个字符不像GIF89
如何用文件的第一个字符检测到我的文件是*.jpeg?
当我尝试编辑像这样的字符指针的值时,我得到访问冲突.我知道,编译器将它定位在只读内存块中,但有没有办法解锁这个像GlobalUnlock()或HeapUnlock()
int main()
{
char* foo = "Hello";
*foo = 'B'
}
Run Code Online (Sandbox Code Playgroud) 我想要一个函数应该每次返回时将全局变量值重置为0.
我知道我可以gVar=0;在每个return语句之前添加,但这不是我想要的方式,因为新开发人员可能没有这些信息并且可能无法重置gVar值.
要求是
global int gVar = 10;
void fun()
{
// Need to modify gVar Here
gVar = 15;
.
.
.
gVar = 20;
if (some condition)
return;
else
return;
..
// more return possible from this function
// also new developer can add more return statement
// i want every time function return it should set gVar=0
}
Run Code Online (Sandbox Code Playgroud) 当没有返回语句时,int类型返回语句的返回值是什么
为什么?
int func()
{
printf("Hello");
}
int func1()
{
}
void main()
{
int s,p;
s=func();
p=func1();
printf("%d %d", s, p);
}
Run Code Online (Sandbox Code Playgroud)