前提・実現したいこと
今C言語を学んでいるうものです。scanfを使って、空白を含んだ文字を入力することは成功したのですが、その後に内容確認をするためのパートで入力したものをprintfを使って表示したいのですができません。下に書いてある警告が表示されるのですが、解決策がわからず困っています。
発生している問題・エラーメッセージ
エラーメッセージ
warning: unknown conversion type character '[' in format [-Wformat=]
printf("Middle initial(s): %2s%[^\n]", uName.middleInitial);
^
warning: unknown conversion type character '[' in format [-Wformat=]
printf("Last name: %2s%[^\n]", uName.lastName);
^
warning: unknown conversion type character '[' in format [-Wformat=]
printf("Street name: %2s%*[^\n]", uAddress.street);
該当のソースコード
//contacts.h struct Name { char firstName[31]; char middleInitial[7]; char lastName[36]; }; struct Address { int streetNumber; char street[41]; int apartmentNumber; char postalCode[8]; char city[41]; }; struct Numbers { char cell[11]; char home[11]; char business[11]; }; ``````ここに言語を入力 ```C #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include "contacts.h" int main(void) { struct Name uName; struct Address uAddress; struct Numbers uNumbers; char choice; printf("Contact Management System\n"); printf("-------------------------\n"); printf("Please enter the contact's first name: "); scanf("%s",uName.firstName); printf("Do you want to enter a middle initial(s)? (y or n): "); do { scanf("%c", &choice); if (choice == 'y' || choice == 'Y') { printf("Please enter the contact's middle initial(s): "); scanf("%2s%*[^\n]", uName.middleInitial); } } while (choice=='\n'); printf("Please enter the contact's last name: "); scanf("%2s%*[^\n]", uName.lastName); printf("Please enter the contact's street number: ");//street num scanf("%d", &uAddress.streetNumber); printf("Please enter the contact's street name: ");//street name scanf("%2s%*[^\n]", uAddress.street); printf("Do you want to enter an apartment number? (y or n): ");¥ do { scanf("%c", &choice); if (choice == 'y' || choice == 'Y') { printf("Please enter the contact's apartment number: ");//apartment num scanf("%d", &uAddress.apartmentNumber); } } while (choice=='\n'); printf("Please enter the contact's postal code: "); scanf("%2s%*[^\n]",uAddress.postalCode); printf("Please enter the contact's city: "); scanf("%2s%*[^\n]", uAddress.city); //end // Contact Numbers printf("Do you want to enter a cell phone number? (y or n): "); do { scanf("%c", &choice); if (choice == 'y' || choice == 'Y') { printf("Please enter the contact's cell phone number: "); scanf("%s", uNumbers.cell); }; } while (choice=='\n'); printf("Do you want to enter a home phone number? (y or n): "); do { scanf("%c", &choice); if (choice == 'y' || choice == 'Y') { printf("Please enter the contact's home phone number: "); scanf("%s", uNumbers.home); }; } while (choice=='\n'); printf("Do you want to enter a business phone number? (y or n): "); do { scanf("%c", &choice); if (choice == 'y' || choice == 'Y') { printf("Please enter the contact's business phone number: "); scanf("%s", uNumbers.business); }; } while (choice=='\n'); //end //Contact Summary Details printf("\n"); printf("Contact Details\n"); printf("---------------\n"); printf("Name Details:\n"); printf("First name: %s\n", uName.firstName); printf("Middle initial(s): %2s%*[^\n]", uName.middleInitial); printf("Last name: %2s%*[^\n]", uName.lastName); printf("Address Details:\n"); printf("Street number: %d\n", uAddress.streetNumber); printf("Street name: %2s%*[^\n]", uAddress.street); printf("Apartment: %d\n", uAddress.apartmentNumber); printf("Postal code: %s", uAddress.postalCode); printf("City: %s\n\n", uAddress.city); printf("Phone Numbers:\n"); printf("Cell phone number: %s\n", uNumbers.cell); printf("Home phone number: %s\n", uNumbers.home); printf("Business phone number: %s\n\n", uNumbers.business); // Completion Message printf("Structure test for Name, Address, and Numbers Done!\n"); return 0; }