This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Deletes characters from text files

¿I can delete specific characters of a text file? for example, i have a file text with "123456". I'd like delete the number '3' only. ¿what function can i use?

Parents
  • #include <windows.h>
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
      FILE *f;
    
      char *buffer;
      size_t size;
    
      f = fopen("temp.txt","rb");
    
      if (f)
      {
        fseek(f, -1, SEEK_END);
        size = ftell(f);
        fseek(f, 0, SEEK_SET);
        buffer = malloc(size);
        fread(buffer, size, 1, f);
        fclose(f);
    
    
        f = fopen("temp.txt","wb");
    
        if (f)
        {
          fwrite(buffer, size, 1, f);
          fclose(f);
        }
    
        free(buffer);
      }
    
    // Other architectures might permit
    
    //    fseek(f, -1, SEEK_END);
    //    fwrite((void *)f, 0, 0, f);
    
    //    fseek(f, -1, SEEK_END);
    //    ftruncate(f);
    
      return(1);
    }
    

Reply
  • #include <windows.h>
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
      FILE *f;
    
      char *buffer;
      size_t size;
    
      f = fopen("temp.txt","rb");
    
      if (f)
      {
        fseek(f, -1, SEEK_END);
        size = ftell(f);
        fseek(f, 0, SEEK_SET);
        buffer = malloc(size);
        fread(buffer, size, 1, f);
        fclose(f);
    
    
        f = fopen("temp.txt","wb");
    
        if (f)
        {
          fwrite(buffer, size, 1, f);
          fclose(f);
        }
    
        free(buffer);
      }
    
    // Other architectures might permit
    
    //    fseek(f, -1, SEEK_END);
    //    fwrite((void *)f, 0, 0, f);
    
    //    fseek(f, -1, SEEK_END);
    //    ftruncate(f);
    
      return(1);
    }
    

Children