2014-10-30 3 views
0

단어를 'GONE'으로 바꾸려면 코드를 작성해야한다고 생각합니다.C에서 txt 파일의 단어를 바꾸는 방법은 무엇입니까?

질문 : 어떻게 주어진 단어를 대체하여 단어로 바꿀 수 있습니까? 표준 입력

나는에 넣어한다면 나는 여러 인수에 대한 혼란 스러워요 // pseduocode

open the file 
while not EOF 
    get a word from the file 
    if word == 'GONE' // or argv[1] 
    word = 'GONE' 
end 

통과 TXT 파일에 사라졌다, 가정합니다.

GONE world and GONE 
I hope its going good 
but i gotta go so GONE 

은 내가 C.에서이 문제를 접근 할 방법에 대한 혼란 스러워요이 파일

Hello world and bob 
I hope it's going good 
but i gotta go so bye 

과 출력을 테스트 할

./a.out hello bob bye < hello.txt 

나는 나의 pseduocode가 비록 올바른 생각합니다.

감사합니다.

+1

문제는 무엇을 인쇄 이제

char sentence[] = "Hello world and bob I hope it's going \ good but i gotta go so bye"; const char *to_replace = "Hello"; const char *replacement = "GONE char *pos = strstr(sentence, to_replace); while (pos != NULL) { //Replace the word here as you now positions if (strstr(sentence, to_replace)){ pos = strstr(sentence, to_replace); }else{ pos = 0; } } 

: 같은 separte 문자열의 텍스트를 저장? –

+0

@BryanChen 인수로 주어진 단어를 대체하고 stdin – dayzNnitez

+0

을 지나친 txt 파일에서 GONE이라는 단어로 바꿀 수있는 방법은 너무 넓습니다. 코드를 작성하지 않습니다. –

답변

-1

나는 당신에게 아이디어를 줄 수 있지만 자신이 있어야한다. 버퍼 대체 버퍼

관련 문제