Inserting At the beginning of a structure in C

0 votes
asked Jul 15 by Rakshit Arora (160 points)
Consider the following structrure

struct participant{
int pno;
char pname[30];
char pemail[30];
char regno[10];
char phone[11]
} P[MAX];

I want to insert values at the beginning of the P array.

1 Answer

0 votes
answered Jul 15 by xDELLx (2,430 points)
/******************************************************************************
Inserting At the beginning of a structure in C
Consider the following structrure

struct participant{
int pno;
char pname[30];
char pemail[30];
char regno[10];
char phone[11]
} P[MAX];

I want to insert values at the beginning of the P array.
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#define MAX 10
struct participant{
int pno;
char pname[30];
char pemail[30];
char regno[10];
char phone[11];
} P[MAX];

int main()
{
    //beginning of array is P[0]
    //so code goes below
    P[0].pno=1234;
    strcpy(P[0].pname,"namespace");
    strcpy(P[0].pemail,"[email protected]");
    strcpy(P[0].regno,"regno:1234");
    strcpy(P[0].phone,"+1 030214554632");
    printf("Hello World");
    

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...