Moved from C++ forum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joker769
    New Member
    • May 2010
    • 2

    #1

    Moved from C++ forum

    hi, ive been searching for a sort of encrypter but more of a custom one... i need something that takes a file and reads every letter then creates a new file and writes the replaced text in it, like such...

    the weather is good today
    -read
    -replace
    -write new file
    -new text write

    (gaw ltrgatv bz pqqn gqkrm)

    ive tried creating new parameters,
    if (text == A || text == a)
    {
    newtext == r
    }
    but each time i try it it fails... all ive found is random password generators and algorithms i found no guides on this either, could someone please help.
  • joker769
    New Member
    • May 2010
    • 2

    #2
    So far ive found this... its close all id have to do is change the word to letter and do t one by one, but this is in c++ and i need c#... also in c# where would i put modified code?
    Code:
     1.
          #include <stdio.h>
       2.
          #include <string.h>
       3.
           
       4.
          #define MAX_LEN_SINGLE_LINE 120 // ?
       5.
           
       6.
          int main()
       7.
          {
       8.
          const char fileOrig[32] = "myOriginalFile.txt";
       9.
          const char fileRepl[32] = "myReplacedFile.txt";
      10.
          const char text2find[80] = "lookforme";
      11.
          const char text2repl[80] = "REPLACE_WITH_THIS";
      12.
           
      13.
          char buffer[MAX_LEN_SINGLE_LINE+2];
      14.
          char *buff_ptr, *find_ptr;
      15.
          FILE *fp1, *fp2;
      16.
          size_t find_len = strlen(text2find);
      17.
           
      18.
          fp1 = fopen(fileOrig,"r");
      19.
          fp2 = fopen(fileRepl,"w");
      20.
           
      21.
          while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
      22.
          {
      23.
          buff_ptr = buffer;
      24.
          while ((find_ptr = strstr(buff_ptr,text2find)))
      25.
          {
      26.
          while(buff_ptr < find_ptr)
      27.
          fputc((int)*buff_ptr++,fp2);
      28.
           
      29.
          fputs(text2repl,fp2);
      30.
           
      31.
          buff_ptr += find_len;
      32.
          }
      33.
          fputs(buff_ptr,fp2);
      34.
          }
      35.
           
      36.
          fclose(fp2);
      37.
          fclose(fp1);
      38.
           
      39.
          return 0;
      40.
          }

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Could you be more specific as to how it fails? eg, can you give us a simple example like:
      The Day After
      abcdefghijklmno pqrstuvwxyz
      amfouxtwpdbznci skqhjeglvyr
      jwu oay axjuq

      which includes the translation index, and how it is failing (the wrong output)?

      Comment

      Working...