Announcement

Collapse
No announcement yet.

Does the PS2SDK support the use of EOF?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does the PS2SDK support the use of EOF?

    Note: I ran this on my PC and it works with the use of EOF and changing the file from "mc0:/Text.txt" to "Text.txt".

    EDIT: Decided to use fread since it operates better for my purposes.

    I am writing a function to read a line of 18 characters and split it into 9 each. Then having while loop print out each line on the screen. However, when I use 'EOF', it just keeps printing out lines as if there is no end of file. So, as my title suggests, is the PS2SDK compatible with EOF? If not, is there an alternative?

    In case your wondering what keeps being written; I can't really make out what it is constantly printing on my TV, but if I run this on linux and change the EOF to NULL (So it wouldn't stop the loop), it prints the last line over and over again.

    Thanks!

    Code:

    Code:
            char Address[9], Data[9];
    	FILE *fp;
    	fp = fopen("mc0:/Test.txt", "r");
    
    	if (fp < 0)
    	{
    		printf("Error, fp < 0");
    		return 0;
    		fclose(fp);
    	}
    	if (fp > 0)
    	{
    		while ( fscanf(fp, "%s %s", Address, Data) != EOF ) {
    		
    		scr_printf("\n	%s, %s \n\n", Address, Data);
    
    		}
    
    	fclose(fp);
    	}
    Text file:

    Code:
    12345678 87654321
    87654321 12345678
    Last edited by dnawrkshp; 08-06-2012, 08:19:26 PM.

  • #2
    It should do EOF just fine. The problem is probably your format. By definition, %s will cause fscanf to read until it finds a whitespace character, and fscanf should ignore whitespace in general. Having a blank in your format is likely troublesome for it, and I expect it's just copying random bytes past the end of your file and stepping all over memory when it writes to your variables. Also, the PS2SDK (official or unofficial) may or may not handle the scenarios that PC compilers can handle, so I'd be wary of doing oddball things with format strings.
    Last edited by Pyriel; 08-06-2012, 08:14:21 AM.

    Comment


    • #3
      That may be true, but I found a way to get around that.

      Code:
              char Address[9], Data[9];
      	FILE *fp;
      	fp = fopen("mc0:/Test.txt", "r");
      
      	if (fp < 0)
      	{
      		printf("Error, fp < 0");
      		return 0;
      		fclose(fp);
      	}
      	if (fp > 0)
      	{
      		while ( fscanf(fp, "%s %s", Address, Data) == 2 ) {
      		
      		scr_printf("\n	%s, %s \n\n", Address, Data);
      
      		}
      
      	fclose(fp);
      	}
      Also, do you know how I could start using smap? I tried converting the irx module to *.o and then added it to the EE_OBJS in the Makefile. Copied the smap.h and types.h to my folder with the Makefile. Wrote a little main.c with #include <smap.h>, <debug.h>, and some other stuff and then quick printf() and SMapInit(IP, NETMASK, ROUTERIP); (I forgot what the 3rd arg is actually called). I got an error in the compiler that said something like "in main.c:##: undefined reference to SMapInit". If you don't have a clue on how to fix this I will make a new thread since this is off topic. Thanks again Pyriel.

      Comment


      • #4
        As a side note, fopen() returns a file pointer on completion and NULL to indicate an error. So fp < 0 and fp > 0 should be fp == NULL and fp != NULL (use "else" here).

        Comment

        Working...
        X