101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Structure Example
DESCRIPTION: Structure Example
Submitted: 09-Apr-2008 10:18:54 ( 38w 6d 0h ago ) Language: C++ (*.cpp *.h)
Views: 115 Lines of Code: 42 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Advanced
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Structure
   History: 
*/


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

typedef struct
{
	char name[6];
	int roll;
}student;
void main()
{
	student *p;
	int n,i,temp;
	FILE *k;
	k=fopen("k.txt","w");
	printf("enter the numbe of students ");
	scanf("%d",&n);
	p=(student *)malloc(n*sizeof(student));
	for(i=0;i<n;++i)
	{
		printf("enter the name of student %d ",i+1);
		scanf("%s",(p+i)->name);
		printf("enter the roll number of student %d ",i+1);
		scanf("%d",&(p+i)->roll);
	}
	for(i=0;i<n;++i)
	{
		printf("\n name of student %d is %s",i+1,(p+i)->name);
		printf("\n roll number of student %d is %d",i+1,(p+i)->roll);
	}
	getch();
	fclose(k);
}