Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplaying numbers and strings from a structure in c
    primarykey
    data
    text
    <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; struct Directory { char Name; long int Number; int HouseNumber; char street; }; int main(void) { struct Directory contact; struct Directory *answer1, *answer2, *answer3, *answer4; char answer; printf("Welcome to Telephone Directory.\n\nPlease enter the name of the contact.\n"); scanf("%s", &amp;contact.Name); printf("Please enter the number of the contact.\n"); scanf("%ld", &amp;contact.Number); printf("Please enter the address of the contact.\n"); scanf("%d %s", &amp;contact.HouseNumber, &amp;contact.street); answer1 = &amp;contact; answer2 = &amp;contact; answer3 = &amp;contact; answer4 = &amp;contact; printf("Would you like to obtain information on your contact? Enter 'yes' or 'no'.\n"); scanf("%s", &amp;answer); if (strcmp(&amp;answer, "yes")==0) { printf("%s\n", &amp;answer1-&gt;Name); printf("%ld\n", answer2-&gt;Number); printf("%d", answer3-&gt;HouseNumber); printf("%s", &amp;answer4-&gt;street); } if (strcmp(&amp;answer, "no")==0) { printf("Thank you for using Telephone Directory.\n"); } } </code></pre> <p>I'm trying to make a contacts program in C. I want the program to print the user's house address. I have the "HouseNumber" variable in the structure and the "street" variable in the structure, setting "answer3" as an int variable to display the "HouseNumber" and "answer4" as a char variable to display "street". Together, I was hoping they will print the user's address in a single string, but when I run the program and enter "yes" to display the contact information after entering the house number and street, the program crashes, and displays lldb with a bad thread error. It seems like everything is right, because my compiler says that there are no issues with the code, but it crashes. Can somebody please help me with this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload