结构混乱 [英] struct confusion

查看:117
本文介绍了结构混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个函数,它接受的标题和一书的作者,并返回0或1,如果它是可用的,通过将它们与结构的给定阵列比较.....
编译器显示:

I want to make a function which takes the title and the author of a book and returns 0 or 1 if it is available or not, by comparing them with a given array of structs..... Compiler shows:

structs.c:10:28: error: expected ‘)’ before ‘title’
structs.c: In function ‘main’:
structs.c:59:21: error: expected expression before ‘bookRecord’
structs.c:60:13: error: expected expression before ‘bookRecord’
structs.c:61:9: warning: implicit declaration of function ‘requestBook’
structs.c:61:23: error: expected expression before ‘bookRecord’

下面是code:

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


 #define TRUE 1
 #define FALSE 0

 #define NUM_BOOKS 5

 int requestBook(bookRecord title[],bookRecord author[]){    /* compiler error :10*/
          int i;
          for(i=0;i<=NUMBOOKS;i++){
                  if(strcmp(stacks[i].tittle ,bookRecord.title[0]) == 0 &&                                                                              
                  strcmp(stacks[i].author     ,bookRecord.author[0]) == 0 ){

                  return 1;
                   }
           }
                   return 0;
  }

         typedef struct {
        int minute; 
        int hour;   
         } timeT;


    typedef struct {

       char title[50];  
       char author[50];     
       int year;        
       int isOut;                   
       timeT time;      
       int isBlank;         
  } bookRecord;


  /* given array of struct */

    bookRecord stacks[NUM_BOOKS]=
       {
       {"C How To Program", "Deitel", 2006, FALSE, {0,  0}, TRUE} ,
       {"The Old Capital", "Yasunari Kawabata", 1996, FALSE, { 0, 0}, TRUE},
       {"", "", 0, FALSE, {0,0}, FALSE},
       {"", "", 0, FALSE, {0,0}, FALSE},
       {"", "", 0, FALSE, {0,0}, FALSE}
       };

 int main (int argc, char*argv[]) { 
    int t;

    scanf("%s ",bookRecord.title[0]);         /* compiler error :59*/
    scanf("%s",bookRecord.author[0]);     /* compiler error :60*/

     t=requestBook(bookRecord.title[0], bookRecord.author[0]);   /* compiler error :61
     printf("%d",t);


     return 0;
 }

任何帮助AP preciated!

Any help appreciated !

/////////////////////////////////////////////// /

////////////////////////////////////////////////

如果你想看到最终的解决方案,请访问STRUCT惑(2)是DUPLICATE

IF YOU WANT TO SEE THE FINAL SOLUTION PLEASE VISIT STRUCT CONFUSION(2) IT IS DUPLICATE

/////////////////////////////////////////////// /

////////////////////////////////////////////////

推荐答案

有几个问题你code。

There are several problems with you code.


  1. 您声明结构的之后的你在 requestBook 函数中使用它们。

  2. requestBook 函数,你参考,到目前为止,未声明的变量堆栈

  3. 在您使用 requestBook 函数的键入 bookRecord 作为一个变量。

  1. You declare the structures after you use them in the requestBook function.
  2. In the requestBook function you reference the, so far, undeclared variable stacks.
  3. In the requestBook function you use the type bookRecord as a variable.

有可能更多,但是这是我能在我的一读发现。

There are probably more, but that was what I could find in my first reading.

编辑:

一对夫妇的其他问题:


  1. requestBook 函数你循环的一次性许多的。请记住,数组索引是从0到(number_of_entries - 1)。

  2. 您使用类型 bookRecord 作为一个变量以及

  3. 当你错误地使用 bookRecord 你没有得到一个结构或字符串,你得到的第一个字符的字符串标题作者

  1. In the requestBook function you loop one time to many. Remember that array indexes are from zero to (number_of_entries - 1).
  2. You use the type bookRecord as a variable in main as well.
  3. When you erroneously use bookRecord you do not get a structure or a string, you get only the first character in the strings title and author.

这篇关于结构混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆