...

View Full Version : need help with my program



enochcheng
12-03-2004, 01:23 PM
It's a crossword puzzle
if you not use the import function
everything is fine
but when importing questions from file
it becomes strange
would you please help me to figure out what's going on

attached the files in puzzle.zip
program project.exe
sourcecode project.c
import file file.txt

aman
12-03-2004, 11:32 PM
Just narrow down the code segments you are having problems with and post those.

enochcheng
12-05-2004, 08:11 AM
i originally works well
but become strange after add the following code
int file(char filename[])
{
int i,j,ch,max,set=3;
FILE *fp;
fp=fopen(filename,"r");
if(!fp)
return 0;
/* No. of questions in the file */
fscanf(fp,"%d",&max);
/* Import Words List */
for(i=set*7+1;i<set*7+1+max;i++)
{
for(j=0;j<3;j++)
fscanf(fp,"%d",&words[i][j]);
getc(fp);
for(j=3;(ch=getc(fp))!='\n';j++)
words[i][j]=ch;
words[i][j+1]=127;
}
for(j=0;j<7-max;j++)
words[i+j][0]=127;
words[i+j][0]=32;
/* Import Shade List */
clear_shading[set*7][0]=0;
clear_shading[set*7][1]=127;
for(i=set*7+1;i<set*7+7;i++)
{
j=0;
do
{
fscanf(fp,"%d",&clear_shading[i][j]);
j++;
}while(clear_shading[i][j-1]!=127);
}
/* Import Question Order */
question_no[set+1][0]=0;
for(i=1;i<=max;i++)
fscanf(fp,"%d",&question_no[set+1][i]);
getc(fp);
/* Import Answer Order */
answer_no[set+1][0]=0;
for(i=1;i<=max;i++)
fscanf(fp,"%d",&answer_no[set+1][i]);
getc(fp);
/* Print Questions */
for(i=1;i<=max;i++)
{
printf("%d. ",i);
while((ch=getc(fp))!='\n'&&ch!=EOF)
printf("%c",ch);
printf("\n");
}
fclose(fp);
return max;
}

where words[][] clear_shaind[][] question_no[][] answer_no[][] are global variables

aman
12-05-2004, 07:33 PM
What becomes strange? Narrow it down to the exactly where it goes wrong. Usually when writing code like that you should write small amounts at a time, and test as you go.

enochcheng
12-06-2004, 11:16 AM
everything works fine if i not add that part of code
however
if that part is run
then the program can't print out question no. and question of set 1
i duno what's happening

aman
12-09-2004, 02:46 AM
Like I said, you need to start slower. Comment out the body of that function and start adding sections, testing as you go. You make it harder than it needs to be by writing a big function then trying to figure out where it goes wrong.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum