c - 尝试编写一段简单的结构基础代码...没有得到?

标签 c

抱歉,我认为我真的搞砸了几行基于结构的代码...因为我是新人,最近几天努力理解 C。请检查以下代码并指导我哪里错了...谢谢!

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


struct family{

       char name[20];
       int age;
       char father[20];
       char mother[20];

       };

 //Function to compares two strings and returns 1 or 0  

char siblings(struct family member1, struct family member2)
{
     if(strcmp(member1.mother, member2.mother)==0)
         return 1;
     else
         return 0;
 }

int main()
{

//Following structure variables are decleared

    struct family member1;
    struct family member2;

  //structure variables initilized with a string

    member1.mother = "Rosy";
    member2.mother = "Rosy";

//This function compares two strings and returns 1 or 0

    siblings(member1.mother, member2.mother);

//trying to print resulst with respect to return from function 

     printf("%S\n",siblings(member1.mother, member2.mother)?"yes":"No");


    system("PAUSE");
    return 0;
}

最佳答案

替换以下内容:

1-1:%S 应替换为 %d

printf("%S\n",siblings(member1.mother, member2.mother)?"yes":"No");

1-2:如果返回 0 或 1,则返回 boolint 更有意义。

char siblings(struct family member1, struct family member2)

2:“PAUSE”应该是“暂停”

system("PAUSE");

3:使用strcpy进行以下操作。

member1.mother = "Rosy";
member2.mother = "Rosy";

关于c - 尝试编写一段简单的结构基础代码...没有得到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15400497/

相关文章:

c - 我的代码没有正确反转每个单独单词的字符串?

c - int LA[] = {1,2,3,4,5} c 中的内存分配困惑

c - 使用数组的堆栈实现

c - 如何给字符串赋值?

c - 如果该结构作为数组存在,是否可以仅从该结构发送一个变量?

C 结构运算符

C 数组声明语法

c - 内联汇编器: Pass a constant

c - 在二维数组中赋值时出错

c++ - 如何将 C/C++ 库代码封装为可在具有多个实例的单独线程中运行?