|
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
Marcina
Joined: 15 Aug 2006 Posts: 26 Location: Rīga
|
Posted: 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!!!!
Es ticu, ka kļūda ir stulba!
Bet kur tā ir! |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: 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 |
|
|
Marcina
Joined: 15 Aug 2006 Posts: 26 Location: Rīga
|
Posted: Wed Dec 27, 2006 11:14 pm Post subject: |
|
Man atliek pateikt tikai Paldies! |
|
Back to top |
|
|
|
|
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
|