#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cognome=NULL;
char *nome=NULL;
char *email=NULL;
char *password=NULL;
char *password2=NULL;
FILE *file_utenti=NULL;
file_utenti=fopen("Utenti.dat","a+");
struct utente
{
char cognome[25];
char nome[25];
char email[80];
char password[64];
char password2[64];
};
struct utente Utente;
file_utenti=fopen("Utenti.dat","r");
if(file_utenti!=NULL)
printf("%s\n","File aperto correttamente in lettura");
else
printf("%s\n","Impossibile leggere sul file utenti");
while(fread(&Utente, sizeof(Utente), 1, file_utenti))
{
printf("%s\t",Utente.cognome);
printf("%s\t",Utente.nome);
printf("%s\t",Utente.email);
printf("%s\t",Utente.password);
printf("%s\t",Utente.password2);
printf("\n");
}
fclose(file_utenti);
return 0;
}
如果我以CGI脚本运行,它不会输入时,但是如果我在/var/www/www/cgi-bin/目录中运行它,它可以很好地工作。它打开文件,打印所有记录,然后退出 当然,我在CGI脚本中使用了HTML标签。我的意思是,我使用表显示文件中的数据 但这只写标签表
以下提出的代码:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct utente
{
char cognome[25];
char nome[25];
char email[80];
char password[64];
char password2[64];
};
struct utente Utente;
FILE *file_utenti=fopen("Utenti.dat","r");
if( file_utenti )
printf("%s\n","File aperto correttamente in lettura");
else
{ // fopoen failed
perror("Impossibile leggere sul file utenti");
exit( EXIT_FAILURE );
}
while(fread( &Utente, sizeof(Utente), 1, file_utenti) )
{
printf("%s\t",Utente.cognome);
printf("%s\t",Utente.nome);
printf("%s\t",Utente.email);
printf("%s\t",Utente.password);
printf("%s\t",Utente.password2);
printf("\n");
}
fclose(file_utenti);
return 0;
}
wo,这个问题不能澄清每个字符串是否是通过NUL字节终止的。 如果未由NUL字节终止,则代码将输出垃圾。
trory要为您的文件名称“ UTENTI.DAT”的绝对路径, 例如“/var/www/cgi-bin/utenti.dat”或该文件所在的任何地方。
行更改:file_utenti = fopen(“ utenti.dat”,“ a+”)实际上,Web服务器的默认路径可能是 /var /www,这就是为什么它在此路径中找不到您的文件。