Thread: What is wrong with this code!!!

  1. #1
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784

    What is wrong with this code!!!

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<wchar.h>
    
    int wmain( ) 
    {
    	//wchar_t c;
    	wchar_t c;
    
    	FILE *fptr = fopen("c:\\Accountsout.txt","r");
    	if(fptr == NULL) 
    	{
    		printf("Error");
    		exit(1);
    	}
    
    	while( fwscanf(fptr,L"%C", &c)!= EOF) 
    	{
    		wprintf(L"%C \n",c);
    	}
    
    	fclose(fptr);
    	return 0;
    }
    ??????
    Last edited by Troll_King; 10-18-2001 at 12:36 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try posting on the "windows programming" board.

    Actually, I can tell you your problem:

    > while( fwscanf(fptr,L"%C", &c)!= EOF)

    What you're doing here is saying:

    "compare the return value of "fscanf()" with "EOF"

    This is not what you want.
    Code:
    do {
       fwscanf( fptr, L"%C", &c )
       if( c != EOF )
          wprintf(L"%C \n",c);
    } while( c != EOF );
    Quzah.

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Your code is wrong. Anyways I may post this on the Windows board but I'm trying to scan a file with special characters like in the question on this board.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How's it wrong? It's your code stuck into a 'do while' instead of a 'while'. The reason I suggested the windows board is because I'm unsure of the return values of those 'w' functions.

    Quzah.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    It returns EOF if it reads the 'end of file'. It does not store EOF in the variable. It is the same as fscanf which I have used many times so I know that the syntax is correct. The only difference is that it may return WEOF instead of EOF. But it still didn't run. I did post this on the windows programming board. So how does one scan a textfile for unicode characters (16 bit).

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > So how does one scan a textfile for unicode characters (16 bit).

    One byte at a time, with byte-by-byte comparisons. (Or, just
    16 bits at a time, with 16bit numerical comparison.) (You just
    can't expect to be able to use standard 'string' functions on
    them.)

    Quzah.

  7. #7
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I think it scans 16 bits at a time. It can do comparisons but not standard C comparisons. It has it's own special functions for that. I just wanted to be able to scan that special character. Maybe unicode can only scan files that were created by the computer just like binary files. That could be a plausable explanation why it didn't work on the plain text file. It may need some special formatting.

  8. #8
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Believe it or not there is a wcscmp() and a wcscpy(). Basically everything can be done. Cool.

  9. #9
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    is it there in C89 ? Is it there in C99 ? What header files have to be included ?

  10. #10
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    #include<wchar.h>
    #include<wctype.h>

    It's all over C9899. I have this document. This is pure ISO/IEC.
    Last edited by Troll_King; 10-18-2001 at 06:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM