gpt4 book ai didi

c - 错误 : called object type 'ssize_t' (aka 'long' ) is not a function or function pointer

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:19 52 4
gpt4 key购买 nike

我在 C 编程方面不是很有经验,我正在尝试使用管道编写程序。问题是,当我尝试编译它时,它给了我一个我无法理解的奇怪错误,即使通过阅读 Stackoverflow 中的其他类似问题也是如此。

错误是下一个:

ejercicio.c:91:8: error: called object type 'ssize_t' (aka 'long') is not a function or function pointer
read(tuberiaCom[0], login, sizeof(int));
~~~~^
ejercicio.c:103:8: error: called object type 'ssize_t' (aka 'long') is not a function or function pointer
read(tuberiaCom[0], *checkuser, 256);

受影响的代码是这个:

int main(){
int tuberiaCom[2];
int fduser;
int login = 0;
char username[256];
char answer[1024];
char checkuser[256];
char command[64];
char program[16];
char options[48];
char *line = NULL;
pid_t familia;
size_t len = 0;
ssize_t read;

if(pipe(tuberiaCom) == -1){
fprintf(stderr, "Pipe error\n");
exit(1);
}

switch(familia = fork()){
case -1:
fprintf(stderr, "Fork error\n");
exit(1);
break;
case 0:
scanf("Please, write your username %s", username);

write(tuberiaCom[1], &username, strlen(username));
read(tuberiaCom[0], login, sizeof(int)); /////////Line 91

if(login == 1){
printf("User %s exists, you can continue", username);
}
else{
printf("There is no user called %s, the program will finnish", username);
exit(1);
}

break;
default:
read(tuberiaCom[0], *checkuser, 256); /////////Line 103
fduser = open("users.txt", O_RDONLY);

while ((read = getline(&line, &len, fduser)) != -1){
if(*line == *checkuser){
login = 1;
break;
}
}

write(tuberiaCom[1], &login, sizeof(int));

break;
}
......

最佳答案

您有一个名为 read 的变量,当您调用 read(2) 时,它会使编译器与函数 read(2) 混淆。将您的变量 read 重命名为其他名称。

关于c - 错误 : called object type 'ssize_t' (aka 'long' ) is not a function or function pointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47057353/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com