Notice: Undefined offset: 1886682 in /var/www/html/qa-external/qa-external-users.php on line 744
Inserting At the beginning of a structure in C - OnlineGDB Q&A
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

+1 vote
answered Jul 15, 2020 by (10,560 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,"pemail@pname.com");
    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 receive answers from other members of the community.
...