C初心者はここで、これを解決するために苦労します。同じタイプの構造要素を反復する
私は現在、構造データを出力する機能を構築していますが、データが存在するかどうかをチェックする前に出力しています。
これは私の現在のソリューションである:ここ
if (strcmp(P.strFullName.arcTitle, " ") != 0)
printf("%s ", P.strFullName.arcTitle);
if (strcmp(P.strFullName.arcFirstName, " ") != 0)
printf("%s ", P.strFullName.arcFirstName);
if (strcmp(P.strFullName.arcMiddleName, " ") != 0)
printf("%s ", P.strFullName.arcMiddleName);
if (strcmp(P.strFullName.arcSurname, " ") != 0)
printf("%s ", P.strFullName.arcSurname);
printf("\n");
すべての構造要素は文字列であり、そして私は、理想的にはifとprintfの機能を持つ2本のキーラインをループできるようにしたいと思い、単に変更ループが各インクリメントを調べている構造要素。
これを簡略化する方法はありますか?
構造体に文字列の配列を持っていないのはなぜ、単にループを使用する:あなたがすでに持っていたが、今もこのデータをループすることができるものとそう非常に似
? – Peter
struct defenitionを追加できますか? –
[This Q/A](http://stackoverflow.com/questions/1784782/is-there-any-way-to-loop-through-a-struct-with-elements-of-different-types-in- c)役に立つでしょう。 –