是voidC编程语言中的数据类型吗?如果是这样,它可以存储什么类型的值?如果我们有int,float,char,等,来存储值,为什么void需要?
这是我写的程序,任何人都可以告诉它有什么问题,因为无论我给出什么输入,它都显示有效的用户.
#include<stdio.h>
#include<string.h>
#define max_size 20
void main()
{
File *Fptr;
char username[max_size];
char line[20];
if((fptr=fopen("/etc/passwd","r"))==NULL)
{
printf("cannot open file");
}
else
{
fptr=fopen("/etc/passwd","r");
fputs("enter the username",stdout);
fflush(stdout);
fgets(username,sizeof username,stdin);
while((fgets(line,sizeof(line),fptr))!=NULL)
{
if(strcmp(line,username))
{
printf("%s valid user",username);
break;
}
else
{
printf("%s not valid user",username);
}
}
fclose(fptr);
}
}
Run Code Online (Sandbox Code Playgroud)