小编Dre*_*ann的帖子

将FILE*读入课堂

我试图读取文本文件中的条目并将其放入类中.文本文件的结构如下:

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循环中该做什么.此外,此代码看起来不正确.

我该如何编码呢?

c class file

-2
推荐指数
1
解决办法
98
查看次数

在C++ 11中,获取系统滴答/时间的最快方法是什么?

我的程序经常调用WINAPI函数timeGetTime(),应该替换为<chrono>(标准库)的使用.什么是最快的标准化的方式来获取系统时间-在floatint,我的情况?

我不需要跟踪日期或日期时间,我只需要精确的相对ms /秒值,它总是递增.有没有?

c++ time winapi c++11 c++-chrono

-2
推荐指数
1
解决办法
755
查看次数

如何使用它的内容检测文件格式

如果用记事本打开*.gif文件,文件将以GIF89开头

但是对于*.jpeg文件,第一个字符不像GIF89

如何用文件的第一个字符检测到我的文件是*.jpeg?

c c++

-3
推荐指数
1
解决办法
90
查看次数

如何修改只读内存中的char

当我尝试编辑像这样的字符指针的值时,我得到访问冲突.我知道,编译器将它定位在只读内存块中,但有没有办法解锁这个像GlobalUnlock()HeapUnlock()

int main()
{
    char* foo = "Hello";
    *foo = 'B'
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers

-3
推荐指数
1
解决办法
122
查看次数

我每次从函数返回时都可以重置全局变量的值

我想要一个函数应该每次返回时将全局变量值重置为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)

c variables global function

-3
推荐指数
1
解决办法
199
查看次数

当没有返回语句时,返回int类型返回语句的值

当没有返回语句时,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)

c return function

-5
推荐指数
1
解决办法
133
查看次数

标签 统计

c ×4

c++ ×3

function ×2

c++-chrono ×1

c++11 ×1

class ×1

file ×1

global ×1

pointers ×1

return ×1

time ×1

variables ×1

winapi ×1