-2

こんにちは、私は現在大学でプロジェクトを終えていますが、文字列の長さを 13 に設定する必要があります。これにより、文字列が 13 より短いか長い場合にエラー メッセージが返されます。これまでのコードは次のとおりです。

 void add_new_text_book()
 {
//this option is here to add a new book to the list
printf("Please enter the Title of a new text book\n");
scanf("%s",book[number_of_books].title);
printf("Please enter the Authors firstname\n");
scanf("%s",book[number_of_books].firstname);
printf("Please enter the Author surname\n");
scanf("%s",book[number_of_books].surname);

printf("Finally please enter the ISBN number of the book\n");
scanf("%s",book[number_of_books].isbn);

if(length_of_string==13)//will be used to check the length of the book is valid

{
    if(number_of_books==15)//will check to see how many records have been used
    {
    printf("book not added as you have used all free space\n");
    }else
    {
    printf("Book has been added to the libary\n");
    number_of_books=number_of_books+1;
    }

}else{
printf("You have entered too many or few characters the books has not been saved\n");
}

getch();
    length_of_string=strlen(book[number_of_books].isbn);

しかし、13 と入力してもエラー メッセージが表示され、123-456-789-1 しか受け付けないようです。

4

3 に答える 3

0

"length_of_string" の値は? その値は :123-456-789-1 ですか? もしそうなら、あなたはそれを使うことができます:

if(length_of_string.size()==13)//will be used to check the length of the book is valid


 {
    if(number_of_books.size()==15)//will check to see how many records have been used

 {
    printf("book not added as you have used all free space\n");

  }else

 {
    printf("Book has been added to the libary\n");
    number_of_books=number_of_books+1;

  }

  }
else

    {
  printf("You have entered too many or few characters the books has not been saved\n");

     }

getch();

   }
于 2013-06-17T15:01:27.233 に答える