我正在编写一个程序来快速编写我的 .html 文件。这些 .html 文件主要包含问题和答案。选项为MCQ(多项选择题)形式。第一个问题与这个程序配合得很好,但是当我输入第二个问题时,它向右移动了一个选项卡和选项。我不明白为什么。代码在这里:
int main(){
int track=0;
int thread=0;
int question_no;
char options[4][50];
FILE *fp = fopen ("test.html", "w");
printf("\n\aHow many questions?");
scanf("%d",&question_no);
while((c = getchar()) != '\n' && c != EOF) ;
char question[question_no][100];
for(track=1;track<=question_no;track++)
{
fprintf(fp,"\n<div class=\"question\"> ");
printf("\n\aQuestion number %d.",track);
fgets(question[track-1],sizeof(question[track-1]),stdin);
fprintf(fp,"\nQ%d. %s </div>",track,question[track-1]);
fprintf(fp,"\n<div class=\"options\">");
fprintf(fp,"\n<form>");
for(thread=1;thread<=4;thread++)
{
fprintf(fp,"<label><input type=\"radio\"id=\"q%dop%d\" name=\"q%d\" value=\"q%do%d\">",track,thread,track,track,thread);
printf("\n\aOption. %d:",thread);
fgets(options[thread-1],sizeof(options),stdin);
fprintf(fp,"\n%d. %s",thread,options[thread-1]);
fprintf(fp,"</label><br/>");
}
fprintf(fp,"\n</form>");
}
fclose(fp);
}
您缺少结尾 </div>
.
for(track=1;track<=question_no;track++)
{
fprintf(fp,"\n<div class=\"question\"> ");
printf("\n\aQuestion number %d.",track);
fgets(question[track-1],sizeof(question[track-1]),stdin);
fprintf(fp,"\nQ%d. %s </div>",track,question[track-1]);
fprintf(fp,"\n<div class=\"options\">"); // This div is never closed!
fprintf(fp,"\n<form>");
for(thread=1;thread<=4;thread++)
{
fprintf(fp,"<label><input type=\"radio\"id=\"q%dop%d\" name=\"q%d\" value=\"q%do%d\">",track,thread,track,track,thread);
printf("\n\aOption. %d:",thread);
fgets(options[thread-1],sizeof(options),stdin);
fprintf(fp,"\n%d. %s",thread,options[thread-1]);
fprintf(fp,"</label><br/>");
}
fprintf(fp,"\n</form>");
fprintf(fp,"\n</div>"); // Add this row to close the div
}
}
我是一名优秀的程序员,十分优秀!