What is the error?

This is a discussion on What is the error? within the Windows Programming forums, part of the Platform Specific Boards category; 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) { ...

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

    What is the error?

    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 ) != WEOF)
    	{
    			wprintf(L"%C \n",c);
    	} 
    
    	fclose(fptr);
    	return 0;
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    You didn't sacrify a chicken like I told you... without chicken blood, your compiler will never accept this.






    Now, seriously, what do you want it to do, and what does it do ?
    What kind of errors do you get ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    UNICODE man, that's what. Just UNICODE.

    I looked this up in the C standard and discovered that half the C standard involves UNICODE and I have never seen anyone on this board use it.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    yeah, unicode is useless to me

    i never found a use for it, it's uselsess for the kinda stuff i write

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    If you write for Windows CE, you have no choice other than UniCode, it doesn't support anything else.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Okay, those are the palm computer things. Well, I bet that in the future we could see a lot more unicode being supported and enforced. It makes business sense to have a special character set that supports many languages. I plan on reading more about it.

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    If you are using the MFC, you can use the _T macros to enable your program to be compiled for either UNICODE or ASCII/ANSI by setting the _UNICODE or _MBSC ( multibyte-charset ) #defines.

    Example from the MSDN
    (sorry, I'd post a link, but I don't like to dig around in MS's slooooow page right now, so here goes the copy of my installed Version. If you have it installed, too, look for TCHAR in the index ):


    Code:
    A Sample Generic-Text Program
    Microsoft Specific >
    
    The following program, GENTEXT.C, provides a more detailed 
    illustration of the use of generic-text mappings defined in 
    TCHAR.H:
    
    /* 
     * GENTEXT.C: use of generic-text mappings defined in TCHAR.H
     *            Generic-Text-Mapping example program
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <direct.h>
    #include <errno.h>
    #include <tchar.h>
    
    int __cdecl _tmain(int argc, _TCHAR **argv, _TCHAR **envp)
    {
       _TCHAR buff[_MAX_PATH];
       _TCHAR *str = _T("Astring");
       char *amsg = "Reversed";
       wchar_t *wmsg = L"Is";
    
    #ifdef _UNICODE
       printf("Unicode version\n");
    #else /* _UNICODE */
    #ifdef _MBCS
       printf("MBCS version\n");
    #else
       printf("SBCS version\n");
    #endif
    #endif /* _UNICODE */
    
       if (_tgetcwd(buff, _MAX_PATH) == NULL)
           printf("Can't Get Current Directory - errno=%d\n", errno);
       else
           _tprintf(_T("Current Directory is '%s'\n"), buff);
       _tprintf(_T("'%s' %hs %ls:\n"), str, amsg, wmsg);
       _tprintf(_T("'%s'\n"), _tcsrev(str));
       return 0;
    }
    
    If _MBCS has been defined, GENTEXT.C maps to the following MBCS program:
    
    /* 
     * MBCSGTXT.C: use of generic-text mappings defined in TCHAR.H
     *            Generic-Text-Mapping example program
     *            MBCS version of GENTEXT.C
     */
    
    #include <stdlib.h>
    #include <direct.h>
    
    int __cdecl main(int argc, char **argv, char **envp)
    {
       char buff[_MAX_PATH];
       char *str = "Astring";
       char *amsg = "Reversed";
       wchar_t *wmsg = L"Is";
    
       printf("MBCS version\n");
    
       if (_getcwd(buff, _MAX_PATH) == NULL) {
           printf("Can't Get Current Directory - errno=%d\n", errno);
       }
       else {
           printf("Current Directory is '%s'\n", buff);
       }
    
       printf("'%s' %hs %ls:\n", str, amsg, wmsg);
       printf("'%s'\n", _mbsrev(str));
       return 0;
    }
    
    If _UNICODE has been defined, GENTEXT.C maps to the following 
    Unicode version of the program. For more information about using 
    wmain in Unicode programs as a replacement for main, seeUsing 
    wmain in C Language Reference.
    
    /* 
     * UNICGTXT.C: use of generic-text mappings defined in TCHAR.H
     *            Generic-Text-Mapping example program
     *            Unicode version of GENTEXT.C
     */
    
    #include <stdlib.h>
    #include <direct.h>
    
    int __cdecl wmain(int argc, wchar_t **argv, wchar_t **envp)
    {
       wchar_t buff[_MAX_PATH];
       wchar_t *str = L"Astring";
       char *amsg = "Reversed";
       wchar_t *wmsg = L"Is";
    
       printf("Unicode version\n");
    
       if (_wgetcwd(buff, _MAX_PATH) == NULL) {
          printf("Can't Get Current Directory - errno=%d\n", errno);
       }
       else {
           wprintf(L"Current Directory is '%s'\n", buff);
       }
    
       wprintf(L"'%s' %hs %ls:\n", str, amsg, wmsg);
       wprintf(L"'%s'\n", wcsrev(str));
       return 0;
    }
    
    If neither _MBCS nor _UNICODE has been defined, GENTEXT.C 
    maps to single-byte ASCII code, as follows:
    
    /* 
     * SBCSGTXT.C: use of generic-text mappings defined in TCHAR.H
     *            Generic-Text-Mapping example program
     *            Single-byte (SBCS) Ascii version of GENTEXT.C
     */
    
    #include <stdlib.h>
    #include <direct.h>
    
    int __cdecl main(int argc, char **argv, char **envp)
    {
       char buff[_MAX_PATH];
       char *str = "Astring";
       char *amsg = "Reversed";
       wchar_t *wmsg = L"Is";
    
       printf("SBCS version\n");
    
       if (_getcwd(buff, _MAX_PATH) == NULL) {
           printf("Can't Get Current Directory - errno=%d\n", errno);
       }
       else {
           printf("Current Directory is '%s'\n", buff);
       }
    
       printf("'%s' %hs %ls:\n", str, amsg, wmsg);
       printf("'%s'\n", strrev(str));
       return 0;
    }
    
    See Also   Generic-text mappings, Data type mappings, Constants 
    and global variable mappings, Routine mappings, Using generic-
    text mappings
    
    END Microsoft Specific
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21