-4


最初:私はポインターの初心者です。
ポインター配列の文字列の文字を出力したいだけです。それは正常に動作しますが、Eclipse Juno (Mac OS X) で 2 つの問題が発生し
ます

#include<stdio.h>
#include<string.h>

int main(void)
{
    char *words[] = {"word1", "word2", "word3", "word4", "word5"};
    char *tempWord,*tempChar;
    int i, j, numElems2;

    int numElems = sizeof words / sizeof words[0];
    for(i = 0; i < numElems; ++i)
    {
        tempWord = words[i];
        numElems2 = strlen(tempWord);

        for(j = 0; j < numElems2; ++j)
        {
            tempChar = tempWord[j];
            printf("%c", tempChar);
        }
        printf("\n");
    }

    return 0;
}

I understand the first problem, but don't know how to solve it. The second problem I don't understand. What has a 'char' to do with 'int'?

Maybe there is somebody who can give me some advice. Thanks.

4

2 に答える 2

4

tempCharあなたが現在持っているようにcharではなく、である必要があります。char *

両方の警告メッセージがこれを示しています。

于 2012-11-23T14:53:56.510 に答える
3

このコードが何をすべきかはわかりませんが、最初に tempChar は *char ではなく char 型でなければなりません。printf で文字列を出力したい場合は、"%s" を使用する必要があります...

于 2012-11-23T15:00:29.590 に答える