我是C语言的学习者,我需要使用shellforge编译代码,因此不能使用任何库函数,因为它们会提供错误。
有人可以帮我吗?
到目前为止,这是我所拥有的,在比较两个密码并将其写入文件之前,我需要帮助。为实现此目的而对我的代码进行的任何帮助/修改,并附带解释,将不胜感激。
#include <stdio.h>
int main()
{
int fd;
char username;
char kbinput[KBINPUT_SIZE];
char kbinputpassone[KBINPUTPASSONE_SIZE];
char kbinputpasstwo[KBINPUTPASSTWO_SIZE];
char passwordone;
char passwordtwo;
int count = 0;
int ret;
fd = open("test.txt", O_CREAT | O_RDWR,0666);
if(fd == -1)
{
printf("Error!");
exit(1);
}
write(1,"Enter the username",18);
do
{
read(0, &username, 1);
if (username == '\n')
break;
kbinput[count++] = username;
}
while (count < KBINPUT_SIZE - 1);
kbinput[count] = 0;
write(fd,username,10);
write(1,"Enter the password",18);
count =0;
do
{
read(0, &passwordone, 1);
if (passwordone == '\n')
break;
kbinputpassone[count++] = passwordone;
}
while (count < KBINPUTPASSONE_SIZE - 1);
kbinputpassone[count] = 0;
write(1,"Enter the password again",25);
count=0;
do
{
read(0, &passwordtwo, 1);
if (passwordtwo == '\n')
break;
kbinputpasstwo[count++] = passwordtwo;
}
while (count < KBINPUTPASSTWO_SIZE - 1);
kbinputpasstwo[count] = 0;
write(1,"The Passwords match",20);
write(fd, passwordone, 15);
return 0;
}