문자열에서 단어를 변경하는 방법을 찾고 있습니다. 첫 단어보다 더 많은 기호를 가진 다른 단어로 단어를 변경하고 싶습니다. 먼저 다른 단어로 바꾸고 싶은 단어의 기호를 세웁니다. 이 단어가 내 프로그램에있는 텍스트에 얼마나 많은 문자 배열로 있는지 (문자 배열) 이제이 단어를 변경하고 싶습니다. 더 많은 상징이있는 단어. 이 코드입니다 : 나는 단어가 있었다 입력하면C에서 다른 단어로 문자열의 단어 변경
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
Start:
printf("This program can change word or symbols combanation in text\n\n");
char text[550] = "There was a grocery shop in a town. Plenty of mice lived in that grocery shop.\nFood was in plenty for them. hey also wasted the bread\nbiscuits and fruits of the shop.\nThe grocer got really worried. So, he thought I should buy a cat\nand let it stay at the grocery. Only then I can save my things.\nHe bought a nice, big fat cat and let him stay there. The cat had a nice\nime hunting the mice and killing them.\nThe mice could not move freely now. They were afraid that\n\n";
printf("%s\n", text);
int symbols_in_text = 0;
for (int f = 0;f < 550;f++)
{
if (text[f])
{
symbols_in_text++;
}
else
{
break;
}
}
printf("Text has %i symbols\n\n", symbols_in_text);
char b[15];
printf("Which word would you like to chenge in text above?\n(Maximum quantity of Symbols is 15)\nType word or some symbol(s)\n--->>");
cin >> b;
int word_symbols=0;
for (int a = 0;a < 15;a++)
{
if (b[a])
{
word_symbols++;
}
else
{
break;
}
}
printf("Word which you have entered has %i symbols\n", word_symbols);
int word_in_text = 0;
for (int i = 0; i < 550 - word_symbols; i++)
{
int found = 1;
for (int j = 0; j < word_symbols; j++)
{
if (b[j] != text[i + j])
{
found = 0;
break;
}
}
if (found && text[i + word_symbols]==' ')
{
word_in_text++;
}
}
printf("Founded %i %s as the word an is Not the some part of the other word\n", word_in_text,b);
if (word_in_text != 0)
{
char input_word[15];
printf("Enter the word which you want to insert for first entered word\nWarning:You have to enter the world which have %i symbols\n--->>", word_symbols);
cin >> input_word;
int in_word_symbols = 0;
for (int a = 0;a < 15;a++)
{
if (input_word[a])
{
in_word_symbols++;
}
else
{
break;
}
}
printf("The word which you have entered has %i symbols\n\n", in_word_symbols);
if (word_symbols == in_word_symbols)
{
for (int i = 0; i < 550 - word_symbols; i++)
{
int found = 1;
for (int j = 0; j < word_symbols; j++)
{
if (b[j] != text[i + j])
{
found = 0;
break;
}
}
if (found != 0 && text[i + word_symbols] == ' ')
{
for (int j = 0; j < in_word_symbols; j++)
{
text[i + j] = input_word[j];
}
}
}
printf("The result is--->>\n%s\n\n//////////////////////////////////////////END OF////////////////////////////////////////\n\n", text);
}
else if (in_word_symbols > word_symbols)
{
int text_char_index = 0;
step1:
for (int count = 0; count < 550 - word_symbols; count++)
{
text_char_index++;
int found = 1;
for (int j = 0; j < word_symbols; j++)
{
if (b[j] != text[count + j])
{
found = 0;
break;
}
if (found != 0 && text[count + word_symbols] == ' ')
{
count = text_char_index-1;
goto index_changing;
insert:
for (int c = 0; c < in_word_symbols; c++)
{
text[count + c] = input_word[c];
}
if (count > 500)
{
goto printing_result;
}
else
{
continue;
}
}
}
}
index_changing:
for (int l = 466; l > text_char_index + word_symbols; --l)
{
text[l] = text[l + 1];
}
goto insert;
printing_result:
printf("The result is--->>\n%s\n\n//////////////////////////////////////////END OF////////////////////////////////////////\n\n", text);
}
}
goto Start;
return 0;
}
(- 그것은 내가 텍스트로 변경하고자하는 단어이다) 내가 첫 번째 단어를 입력보다 더 많은 문자가 감지 단어를 (입력보다 - 그것은 내가 답례로 텍스트를 삽입 할 단어입니다) "이었다"
검출 그리고 그런이 코드 방법 또는 뭔가 사용할 수 없습니다 , if() 및 for 루프 만 사용할 수 있습니다. 누구나 어떻게 도와 줄 수 있습니까?콘솔 출력은 다음과 같습니다있다
C 또는 C++? 코드가 두 언어의 끔찍한 혼합으로 보입니까? –
나는 C 언어를 배우고 있지만 scanf()를 모르므로 C++ lib 및 namespace t cin >>을 추가해야합니다. – AlexL
SO는 디버깅 서비스가 아닙니다. 심볼로 컴파일하고 디버거 내부에서 코드를 실행하여 프로그램을 한 줄씩 추적하여 관련 변수의 값을 검사하여 실제 진행 상황을 파악합니다. 만약 * 특정 * 질문이 생기면 여기로 다시 오십시오. – alk