-
weird question
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int number, flag=1;
int w,h,n;
int tall,wide,position,x=0,y=0,a=0;
char line[50],common[50];
FILE *ifp;
void readfile();
main()
{
int x;
while(x!=0)
{
printf("\n (1) ReadFile Function\n ");
scanf("%i",&x);
if (x==1)
{
readfile();
}
}
}
void readfile()
{
if ((ifp=fopen("objects.dat", "r")) == NULL)
{
printf("\n * error opening file objects.dat *");
}
fgets(line,100,ifp);
position=(strlen(line)-1);
while (position>0)
{
if(line[x]==' ')
{ number++; }
position--; x++;
}
number+=1; x=0;
while (number>0)
{
if(line[y]=' ')
{
if (flag==5)
{
n=atoi(common); flag+=1; common==0; x=0; number--; break;
}
if (flag==4)
{
h=atoi(common); flag+=1; common==0; x=0; number--;
}
if (flag==3)
{
w=atoi(common); flag+=1; common==0; x=0; number--;
}
if (flag==2)
{
tall=atoi(common); common==0; flag+=1; x=0; number--; break;
}
if (flag==1)
{
wide=atoi(common); flag+=1; common==0; x=0; number--;
}
}
common[x]=line[y];
y++; x++;
}
printf("\n Number 1: %i",wide);
printf("\n Number 2: %i\n\n\n",tall);
}
this was a function i wrote today but it isn't working properly........it's just telling me Number 1 and 2 = 0.....can anyone run this and tweak with it and an "objects.dat" file to try to make it work?? i know it looks odd but can anyone mess with it real fast? Thanks.
-
-
The first problem is that you defined 'x' globally and set it equal to 0, so it will never enter the while loop in main. If I get time later I'll try to look at it some more.
See ya
-
>int tall,wide,position,x=0,y=0,a=0;
Unnecessary, global variables are initialized the their equivalent of all bits zero automatically.
>if(line[y]=' ')
Oopsie, assignment inside a conditional. You probably meant ==, not =.
-Prelude