Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,265 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,499 people online right now. Registration is fast and FREE... Join Now!




Unexplained output

 
Reply to this topicStart new topic

Unexplained output

aaru_89
15 Oct, 2006 - 05:11 AM
Post #1

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 20



Thanked: 1 times
My Contributions
Hello. Wrote the following code to store phone book details.

CODE

/* Phone book  */

#include<stdio.h>
#include<conio.h>

/* structure declaration  */

struct
{
    char name[50],city[50];
    struct
    {
        char mobn[50],net[50];
    }mob;
    struct
    {
        char lln[50],ser[50];
        int code;
    }ll;
}per[10];

/* main function starts  */

void main()
{
    /* variable declaration  */

    int i,r1,r,n;
    char c='y';

    printf("\n How many entries do you wish to store? ");
    scanf("%d",&n);
    getchar();

    for(i=0;i<n;i++)
    {
        printf("\n Enter name: ");
        fgets(per[i].name,50,stdin);

        printf("\n Enter city: ");
        fgets(per[i].city,50,stdin);

        printf("\n Enter mobile number: ");
        fgets(per[i].mob.mobn,50,stdin);

        printf("\n Enter network provider: ");
        fgets(per[i].mob.net,50,stdin);

        printf("\n Enter city code: ");
        scanf("%d",&per[i].ll.code);
        getchar();

        printf("\n Enter landline number: ");
        fgets(per[i].ll.lln,50,stdin);

        printf("\n Enter service provider: ");
        fgets(per[i].ll.ser,50,stdin);

    }

    while(tolower(c)=='y')
    {
        printf("\n Which record do you wish to review? ");
        scanf("%d",r1);

        r=r1-1;

        printf("\n Name: %s",per[r].name);
        printf("\n City: %s",per[r].city);
        printf("\n Mobile Number: %s",per[r].mob.mobn);
        printf("\n Network provider: %s",per[r].mob.net);
        printf("\n Landline Number: %d %s",per[r].ll.code,per[r].ll.lln);
        printf("\n Service provider: %s",per[r].ll.ser);

        printf("\n Do you wish to continue?(Y/N) ");
        getchar();
        c=getchar();
    }

    printf("\n Have a nice day. Thank you");

    getch();
}








The problem is with the display of required information in the end. Instead of the correct information, it shows some unknown symbols against 'Name: ', 'City: ' etc. Can someone please explai why this happens and how to rectify it. Thank You.
User is offlineProfile CardPM
+Quote Post

aaru_89
RE: Unexplained Output
15 Oct, 2006 - 05:27 AM
Post #2

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 20



Thanked: 1 times
My Contributions
I think I've solved the problem. I'd forgotten to put '&' in one of the scanf() statements. My code works now. Sorry everyone.
User is offlineProfile CardPM
+Quote Post

max302
RE: Unexplained Output
15 Oct, 2006 - 09:12 AM
Post #3

Proud supporter of the lulz
Group Icon

Joined: 5 Mar, 2006
Posts: 1,281


Dream Kudos: 200
My Contributions
Nah, don't worry, I've been having discussions by myself lots of times. Marko can testify.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:22PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month