Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Inserting At the beginning of a structure in C

0 votes
asked Jul 15, 2020 by Rakshit Arora (170 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, 2020 by xDELLx (10,500 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.
...