dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Kur ir kļūda!

 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
Marcina



Joined: 15 Aug 2006
Posts: 26
Location: Rīga

PostPosted: Wed Dec 27, 2006 10:03 pm    Post subject: Kur ir kļūda!

Code:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>

int main(void)
{
   FILE *in;
   int r,k;
   char zp[1];
   clrscr();

   if ((in = fopen("F:\\FIGURA.DAT", "r"))== NULL)
   {
      printf("IN ERROR");
      return 1;
   }

   for(r=0;r<6;r++)
   {
      for(k=0;k<9;k++)
      {
         fscanf(in,"%c",&zp[0]);
         printf ("%i %c\n",k,zp[0]);
      }
   }

   getch();
   fclose(in);
   return 0;
}


Uzdevums jau vienkāršs - tiek pa simbolam ielasīta šāda 9x6matrica:
**.......
*..****..
..******.
..***.**.
...****..
.**......

Gribētos, lai uz ekrāna parādītos katrā jaunā rindiņā kolonnas numurs ar tam matricas atbilstošu simbolu.
Man iznāca, ka ne katram numuram ir klāt simbols!!!! Sad
Es ticu, ka kļūda ir stulba! Very Happy
Bet kur tā ir! Very Happy
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Wed Dec 27, 2006 10:48 pm    Post subject:

Kļūda ir tur, ka tu neizlaid newline \n simbolu. Un tāpēc tas tiek lasīts kā parasts %c.

Pie tam - kāpēc tu tur raksti char zp[1]; un tad &zp[0] ? Var taču vienkārši definēt čaru - char zp; un tad arī to padot fscanf - &zp.

Es to darītu šādi:
Code:
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    FILE *in;
    int r, k;
    char zp;

    if (NULL == (in=fopen("figura.dat", "r")))
    {
        printf("IN ERROR");
        return 1;
    }

    for (r=0; r<6; r++)
    {
        for (k=0; k<9; k++)
        {
            fscanf(in, "%c", &zp);
            printf("%i %c\n", k, zp);
        }
        fscanf(in, "\n");
     }

     fclose(in);
     return 0;
}
Back to top
View user's profile Send e-mail
Marcina



Joined: 15 Aug 2006
Posts: 26
Location: Rīga

PostPosted: Wed Dec 27, 2006 11:14 pm    Post subject:

Man atliek pateikt tikai Paldies! Smile
Back to top
View user's profile
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group