さて、簡単に言えば、問題が発生しています。文字配列 (文字列) の開始アドレスを関数に送信しようとしています。関数がポインタを取得したら、(特定の文字を変更するために) 関数が文字を 1 つずつ解析するようにします。今のところ、各文字を印刷するように設定しただけですが、それでもひどく失敗しています。
これは私が持っているものです:
#include "system.h"
#include <stdio.h>
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void EXCLAIM(char *msg){
char the_char = 0;
the_char = msg;
while (the_char != 0)
{
printf(the_char);
*msg = *(msg++);
the_char = *msg;
}
}
int main(void) {
char *first_str = "This is a test. Will this work. I. am. Not. Sure...";
while (1) {
EXCLAIM(first_str);
}
}
編集:
これが私がやろうとしていた更新されたコードです。ポインターを送信し、すべてのピリオドを感嘆符に置き換えて各文字を調べます。
#include "system.h"
#include <stdio.h>
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void exclaim(char *msg){
int i;
for( i=0; msg[i]; i++ )
{
if (msg[i] == '.') {
msg[i] = '!';
}
}
printf(msg);
}
int main(void) {
char *the_sentences = "This is a test. Will this work. I. am. Not. Sure...";
while (1) {
exclaim(the_sentences);
}
}
ご協力ありがとうございました!