#include<stdio.h>
#include<string.h>
void replace1(char str[], char a[], char b[], char c[], char d[], char e[], char f[], char g[], char h[]){
char str2[99999], *word;
strcpy(str2, str);
for(word = strtok(str2, " "); word != NULL; word = strtok(NULL, " ")){
if (strcmp(word, a) == 0) {
printf("%s ", b);
}
else if(strcmp(word, c) == 0){
printf("%s ", d);
}
else if(strcmp(word, e) == 0){
printf("%s ", f);
}
else if(strcmp(word, g) == 0){
printf("%s ", h);
}
if(strcmp(word, str2) == 0){
for(int i = 0; i < strlen(str); i++){
if(str2[i] >= 'a' && str2[i] <= 'z'){
str2[i] = str2[i] - 32;
}
printf("%c", str[0]);
}
}
}
}
int main(){
char str[99999];
char a[] ="for";
char b[] ="4";
char c[] ="to";
char d[] ="2";
char e[] ="and";
char f[] ="n";
char g[] ="you";
char h[] ="u";
gets(str);
replace1(str, a, b , c, d, e, f, g, h);
}
目前可讓特殊單字轉換成特殊字元,但一般的單字卻無法正確轉換,請問如何使用C語言修改寫法?
#include
#include
void replace1(char str[], char a[], char b[], char c[], char d[], char e[], char f[], char g[], char h[]){
char str2[99999], *word;
strcpy(str2, str);
for(word = strtok(str2, " "); word != NULL; word = strtok(NULL, " ")){
if (strcmp(word, a) == 0) {
printf("%s ", b);
}
else if(strcmp(word, c) == 0){
printf("%s ", d);
}
else if(strcmp(word, e) == 0){
printf("%s ", f);
}
else if(strcmp(word, g) == 0){
printf("%s ", h);
}
if(strcmp(word, str2) == 0){
for(int i = 0; i < strlen(str); i++){
if(str2[i] >= 'a' && str2[i] <= 'z'){
str2[i] = str2[i] - 32;
}
printf("%c", str[0]);
}
}
}
}
int main(){
char str[99999];
char a[] ="for";
char b[] ="4";
char c[] ="to";
char d[] ="2";
char e[] ="and";
char f[] ="n";
char g[] ="you";
char h[] ="u";
gets(str);
replace1(str, a, b , c, d, e, f, g, h);
}
目前可讓特殊單字轉換成特殊字元,但一般的單字卻無法正確轉換,請問如何使用C語言修改寫法?
for(int i = 0; i < strlen(str); i++){
if(str2[i] >= 'a' && str2[i] <= 'z'){
str2[i] = str2[i] - 32;
}
printf("%c", str[0]);
}
應該是printf("%c", str[i]);
#include
#include
void replace1(char str[], char a[], char b[], char c[], char d[], char e[], char f[], char g[], char h[]){
char str2[99999], *word;
strcpy(str2, str);
for(word = strtok(str2, " "); word != NULL; word = strtok(NULL, " ")){
if (strcmp(word, a) == 0) {
printf("%s ", b);
}
else if(strcmp(word, c) == 0){
printf("%s ", d);
}
else if(strcmp(word, e) == 0){
printf("%s ", f);
}
else if(strcmp(word, g) == 0){
printf("%s ", h);
}
if(strcmp(word, str2) == 0){
for(int i = 0; i < strlen(str); i++){
if(str2[i] >= 'a' && str2[i] <= 'z'){
str2[i] = str2[i] - 32;
}
printf("%c", str[0]);
}
}
}
}
int main(){
char str[99999];
char a[] ="for";
char b[] ="4";
char c[] ="to";
char d[] ="2";
char e[] ="and";
char f[] ="n";
char g[] ="you";
char h[] ="u";
gets(str);
replace1(str, a, b , c, d, e, f, g, h);
}
目前可讓特殊單字轉換成特殊字元,但一般的單字卻無法正確轉換,請問如何使用C語言修改寫法?
for(int i = 0; i < strlen(str); i++){
if(str2[i] >= 'a' && str2[i] <= 'z'){
str2[i] = str2[i] - 32;
}
printf("%c", str[0]);
}
應該是printf("%c", str[i]);
謝謝你,我改過了,但還是一樣的問題。