小编Qui*_*k19的帖子

为什么这个方法返回一个包含所有相同对象的ArrayList?JAVA

我有一个叫做的类User和一个名为的文件Users.csv,如下所示:

用户类:

public class User
{
private String name;
private String rg;
private String type;

public String getName()
{
    return name;
}

public String getRg()
{
    return rg;
}

public String getType()
{
    return type;
}

public void setName(String n)
{
    name = n;
}

public void setRg(String r)
{
    rg = r;
}

public void setType(String t)
{
    type = t;
}
}
Run Code Online (Sandbox Code Playgroud)

Users.csv:

a,b,c
d,e,f
as,d,cf
Run Code Online (Sandbox Code Playgroud)

另外,我有一个名为的类test,它实现了一个方法:

考试类:

public class test
{ …
Run Code Online (Sandbox Code Playgroud)

java csv file arraylist bufferedreader

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

错误:“c”的存储大小未知

当我尝试创建名为“struct car”的结构的变量“c”时,出现“错误:‘c’的存储大小未知”

这是代码:

测试文件

#ifndef TESTE_H_INCLUDED
#define TESTE_H_INCLUDED

typedef struct car Car;

#endif // TESTE_H_INCLUDED 
Run Code Online (Sandbox Code Playgroud)

测试程序

#include <stdio.h>
#include <stdlib.h>
#include "teste.h"

struct car{
    char name[20];
    char model[20];

}; 
Run Code Online (Sandbox Code Playgroud)

主程序

#include <stdio.h>
#include <stdlib.h>
#include "teste.h"
int main()
{
    Car c;
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我会收到这个错误...我敢打赌这是愚蠢的事情...有人可以帮助我吗?

c struct adt

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

fread() - 想读取一个整数,但它返回垃圾

我有一个名为library.txt的动态.txt文件,它只有一行数据.正是这一个:

63Book Title1|Book Author 1|Book Editor 1|2014|English|255|99.989998|
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用我创建的void readInteger()函数读取文件上的第一个整数(在本例中为数字"63"):

void readInteger(){
FILE *arq = fopen("library.txt", "r+");
if(arq == NULL){
    printf("ERROR WHILE OPENING FILE!!!");
    return;
}

int x;
fread(&x, sizeof(int), 1, arq);
printf("%d", x);
return;
}  
Run Code Online (Sandbox Code Playgroud)

但该功能始终保持打印疯狂的数字"1866609462".
有谁知道我的代码有什么问题?你能帮帮我吗?

c file fwrite fread

1
推荐指数
1
解决办法
132
查看次数

fwrite()无法在二进制文件中写入整数

有人可以告诉我为什么这个功能不起作用?我只是无法得到它......

void writeRegister(FILE *arq, Book *L){ //writes in actual file position
  char c = '|';
  int sizeRegWrite = reglen(L); //reglen() returns the size of Book
  fwrite(&sizeRegWrite, sizeof(int), 1, arq);

  fwrite(L->TITLE, sizeof(char), strlen(L->TITLE), arq);
  fwrite(&c, sizeof(char), 1, arq); //writing delimiter

  fwrite(L->AUTHOR, sizeof(char), strlen(L->AUTHOR), arq);
  fwrite(&c, sizeof(char), 1, arq); //writing delimiter

  fwrite(L->PUBLISHER, sizeof(char), strlen(L->PUBLISHER), arq);
  fwrite(&c, sizeof(char), 1, arq); //writing delimiter

  fwrite(L->YEAR, sizeof(int), 1, arq);
  fwrite(&c, sizeof(char), 1, arq); //writing delimiter

  fwrite(L->LANGUAGE, sizeof(char), strlen(L->LANGUAGE), arq);
  fwrite(&c, sizeof(char), 1, arq); //writing delimiter

  fwrite(L->PAGES, …
Run Code Online (Sandbox Code Playgroud)

c binary file fwrite

0
推荐指数
1
解决办法
3905
查看次数

标签 统计

c ×3

file ×3

fwrite ×2

adt ×1

arraylist ×1

binary ×1

bufferedreader ×1

csv ×1

fread ×1

java ×1

struct ×1