#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( int argc, char *argv[] )
{
    if ( argc != 4 ) /* argc should be 4 for correct execution */
    {
        /* Print argv[0] assuming it is the program name */
        printf( "usage: %s filename\n", argv[0] );
    }
    else 
    {
        // We assume argv[1] is a filename to open
        char* wordReplace = argv[1];
        char* replaceWord = argv[2]; 
        FILE *file = fopen( argv[3], "r+" );
        /* fopen returns 0, the NULL pointer, on failure */
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
            char string[100];
            int len = 0;int count = 0;int i = 0;int k = 0;
            while  ( (fscanf( file, "%s", string ) ) != EOF )
            {
                len = strlen(string);
                count++;
                char charray[len+1];
                if(count == 1)
                {
                    for (i = 0; i < len; i++)
                    {
                        charray[i] = replaceWord[i];
                        printf("%c\n", charray[i]);
                    }
                }
                //printf("%c\n", charray[0]);
                printf( "%s\n", string );
                if(strcmp(string, wordReplace) == 0)
                {
                    for(k = 0; k < strlen(replaceWord); k++)
                    {
                         fseek (file, (-(long)len), SEEK_CUR);
                         fputc(charray[k],file);
                         //replaceWord++;
                    }
                    //strcpy(string, replaceWord);
                    //fprintf(file,"%s",replaceWord);
                    //fputs(string, file);
                    //printf("\n%d\n", len);
                }       
            }
            fclose( file );
        }
    }
    printf("\n");
    return 0;
}
このコードは現在、最初の単語を適切に置き換える際に機能しますが、置換単語で上書きしたい単語が複数ある場合、または単語がテキストの別の場所に表示されている場合、適切に変更されず、ラムのゴミ箱などに変更されます。 . 誰かが私を感謝の理由に導くことができるかどうか興味がありました.