To Encoding Format of File

This is a discussion on To Encoding Format of File within the C++ Programming forums, part of the General Programming Boards category; Hi All, I have wriiten a c++ code which reads different encoding format file and store in another file.But when ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    Question To Encoding Format of File


    Hi All,
    I have wriiten a c++ code which reads different encoding format file and store in another file.But when i do any manipulation on the file,the following code does not working.
    Can anybody give me the right code.Its urgent!!!!
    Code:
    #include <stdio.h>
    #include<iostream>
    int main()
    {
        FILE *fp, *fw;
        wchar_t *buffer;
        
        if((buffer=(wchar_t *)malloc(sizeof(wchar_t))) == NULL) /* It checks the buffer for the availability of space ,
        to avoid the problem arise due to data overflow */
        {                                                            
            printf("Error: No enough memory\n");
            getchar();
            return 1;
        }
        else
        {
            fp = fopen("in2.txt","rb"); 
            fw = fopen("output_untitled.txt","wb");
        
            if ( fp == NULL  || fw == NULL)
            {
              printf("Error: File cannot be opened\n");
              getchar();
              return 1;
            }
            else
            {
                while(fread(buffer,sizeof(wchar_t),1,fp) > 0)
                   fwrite(buffer,sizeof(wchar_t),1,fw);
            }
        }
        getchar();
        return 0;
    }
    Thanx in Advance
    Samir

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    What does "does not working" mean in this context? How are we supposed to know what errors you are experiencing?

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Your program appears to copy the file "in2.txt" to the file "output_untitled.txt". Apart from not deallocating memory or closing files, I see nothing wrong with it. What exactly is the problem?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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