Thread: weird question

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002

    weird question

    #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();
    	int x;
    		printf("\n (1) ReadFile Function\n  ");
    		if (x==1)
    void readfile()
    	if ((ifp=fopen("objects.dat", "r")) == NULL)
    		printf("\n  * error opening file objects.dat *");
    	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--;
    			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'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.

  2. #2
    Works great!

  3. #3
    Registered User
    Join Date
    Feb 2002
    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

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >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 =.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A weird question.
    By IanKoro in forum C Programming
    Replies: 19
    Last Post: 06-08-2009, 12:00 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Weird Question maybe
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 07:30 PM