0
#include<stdio.h>
#include<string.h>\
struct name
{
        char contact[20];
        long int no;
};
int main()
{
        int i,check;
        char ch[20];
        struct name cse2[10],*p; 
        p=&cse2[10];
        for(i=0;i<10;i++)
        {
                printf("Please enter contact name: ");
                scanf("%s",&(p+i)->contact[20]);
                printf("mobile no: ");
                scanf("%ld",&(p+i)->no);
        }
        
        printf("Please enter a contact name to find his\\her mobile no: ");
        gets(ch);
        for(i=0;i<10;i++)
        {
                check=strcmp(ch,(p+i)->contact[20]);
                if(check==0)
                {
                        printf("Contact name:%s",(p+i)->contact[20]);
                        printf("Mobile no:%ld",(p+i)->no);
                        break;
                }
        }
        return 0;
}
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Moschops
0
contact[20]

is off the end of your array. The last element of your array is contact[19]

p=&cse2[10];

is off the end of your array. The last element of cse2 is cse2[9]

You need to read up on arrays and also the scanf function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.