Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. fopen increment

fopen increment

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju 3
    wrote on last edited by
    #1

    Hi all, I am using fwrite to save some images in while loop. so i a can increment the file in fopen.. like 1.raw,2.raw...3....10 As first paramater is taking const char*. If i take as a CString i am not able to get.

    I tried the below code
    CString FileName = "D:\\"
    sprintf_s(ch,"%d",i++);
    FileName=ch;
    FileName+=".raw";
    FileName=str+FileName;
    then converted CString to char*
    const TCHAR* cstr = (LPCTSTR)FileName;

    It is showing as bad pointer Is there any other way to increment the file name and save all images Here is the Below code:

    FILE *fp_ara;
    while(1)
    {
    fp_ara=fopen ("D:\\1.raw","wb");
    fwrite(Data,2,1024*1024,fp_ara);
    if(fp_ara == NULL)
    exit(1);
    fclose(fp_ara);
    }

    Thank you Sharan

    M _ 2 Replies Last reply
    0
    • M manju 3

      Hi all, I am using fwrite to save some images in while loop. so i a can increment the file in fopen.. like 1.raw,2.raw...3....10 As first paramater is taking const char*. If i take as a CString i am not able to get.

      I tried the below code
      CString FileName = "D:\\"
      sprintf_s(ch,"%d",i++);
      FileName=ch;
      FileName+=".raw";
      FileName=str+FileName;
      then converted CString to char*
      const TCHAR* cstr = (LPCTSTR)FileName;

      It is showing as bad pointer Is there any other way to increment the file name and save all images Here is the Below code:

      FILE *fp_ara;
      while(1)
      {
      fp_ara=fopen ("D:\\1.raw","wb");
      fwrite(Data,2,1024*1024,fp_ara);
      if(fp_ara == NULL)
      exit(1);
      fclose(fp_ara);
      }

      Thank you Sharan

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      me think you are over-complicating things. how about something like :

      for (int i = 0; i < numberOfFile; i++ )
      {
      CString filename;
      filename.Format("c:\\path\\to\\file\\%i.raw", i);

      FILE* fp = fopen( filename, ... );
      /// ... save
      fclose(fp);
      }

      Watched code never compiles.

      1 Reply Last reply
      0
      • M manju 3

        Hi all, I am using fwrite to save some images in while loop. so i a can increment the file in fopen.. like 1.raw,2.raw...3....10 As first paramater is taking const char*. If i take as a CString i am not able to get.

        I tried the below code
        CString FileName = "D:\\"
        sprintf_s(ch,"%d",i++);
        FileName=ch;
        FileName+=".raw";
        FileName=str+FileName;
        then converted CString to char*
        const TCHAR* cstr = (LPCTSTR)FileName;

        It is showing as bad pointer Is there any other way to increment the file name and save all images Here is the Below code:

        FILE *fp_ara;
        while(1)
        {
        fp_ara=fopen ("D:\\1.raw","wb");
        fwrite(Data,2,1024*1024,fp_ara);
        if(fp_ara == NULL)
        exit(1);
        fclose(fp_ara);
        }

        Thank you Sharan

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        I would like to add here that by default the unicode version of CString will be used. This means that you're mixing unicode and non-unicode strings in your code. This will not give you the desired results. If you only want non-unicode characters, you can use CStringA instead of CString. If you want unicode characters, then you will need to change const char* to const wchar_t*, fopen to wfopen and prefix strings with L (L".raw").

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups