Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with my program

    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
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just narrow down the code segments you are having problems with and post those.

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •