C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-12-2008, 03:12 AM   #1
Registered User
 
Join Date: May 2008
Location: IR, Iran
Posts: 101
point to a structure member

hi
can someone help me with this:

Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "struct.h"
//#include "database.txt"

/*****function declaration*****/
void getcmd(char*);
void getpass(char*);
void add_std();
void inf_viewer();
void show_list(student*);

/*****main block*****/
int main()
{
	/* variables define here */
	student std[2];
	char lgn, cmd, std_slct, name, tpass[9], spass[9];
	int i, j;
	
	/**********************************************/
	/* std 1 */

	strcpy(std[0].name,"Behzad Shabani");
	strcpy(std[0].std_num,"860343061");
	std[0].quiz[0] = 18.5;
	std[0].quiz[1] = 17;
	std[0].quiz[2] = 19;
	std[0].exercises[0] = 20;
	std[0].exercises[1] = 18;
	std[0].exercises[2] = 20;
	std[0].project[0] = 20;

	/* std 2 */
	strcpy(std[1].name,"Sepehr Safi");
	strcpy(std[1].std_num,"860343121");
	std[1].quiz[0] = 17.5;
	std[1].quiz[1] = 15;
	std[1].quiz[2] = 13;
	std[1].exercises[0] = 20;
	std[1].exercises[1] = 19;
	std[1].exercises[2] = 17;
	std[1].project[0] = 18;

	/* std 3 */
	strcpy(std[2].name,"Arsalan Barazesh");
	strcpy(std[2].std_num,"860343030");
	std[2].quiz[0] = 17;
	std[2].quiz[1] = 15.5;
	std[2].quiz[2] = 14;
	std[2].exercises[0] = 20;
	std[2].exercises[1] = 19;
	std[2].exercises[2] = 18;
	std[2].project[0] = 17;
	/**********************************************/
	
	/* starting program */
	clrscr();
	printf("Welcome To The Student Database Manager!");
	printf("\nPlease select if you want to login as Student or teacher. (S/T):");
	getcmd(&lgn);
	
	/* checking the command */
	switch (lgn){
		case 'T':
		case 't':

			/* start of teacher function */
			printf("\n\nYou loged in as Teacher.");
			
			/* checking teacher password */
			printf("\nPlease enter your password:");
			getpass(tpass);
			while (strcmp(tpass,"p") != 0){
				printf("\n\aWrong password!\nPlease try again:");
				getpass(tpass);
			}
			
			/* getting a command */
			printf("\n\nSelect one of these action:");
			printf("\n1. Add a student");
			printf("\n2. Delete a student");
			printf("\n3. Edit a student");
			printf("\nEnter number here:");
			getcmd(&cmd);
			
			/* checking the command */
			switch (cmd){
				case '1':
					printf("\n\nadd a student here!");
					add_std();
				break;
				case '2':
					printf("\n\ndelete a student!");
					show_list(std);
					//del_std();
				break;
				case '3':
					printf("\n\nedit a student");
					//edt_std();
				break;
				default:
					printf("\n\n\aUnknown command!");
				break;
			}
			
			//add_inf();
			/* end of teacher function */

		break;
		case 'S':
		case 's':

			/* start of student function */
			clrscr();
			printf("You loged in as Student.");
			printf("\nfind your name from below and enter its number.\n");
			for (i = 0; i<3; i++){
				printf("\n%d.", i + 1);
				puts(std[i].name);
				printf("\n");
			}
			printf("Now enter the number: ");
			scanf("%d", &j);
			i = j - 1;
			printf("\nWelcome ");
			puts(std[i].name);
			printf("\nplease enter your password. (default is your student number): ");
			getpass(spass);
			inf_viewer();
			/* end of student function */
			
		break;
		default:
			printf("\n\aUnknown command!");

		break;
	}

	return 0; // the program succesfully ended
}

/*****function definition*****/

/*****getcmd(): getting commands*****/
// WRITTEN BY: Behzad Shabani
// CALLING FUNCTION: getcmd(&cmd);

void getcmd(char* cmd){

	/* function variables */
	char ch_ctrl;
	int flag = 0;

	/* function process*/
	while (flag == 0){
		*cmd = getche();
		if (*cmd == '\b'){
			printf("\a ");
			continue;
		}
		else if (*cmd == '\r'){
			printf("\a");
			continue;
		}
		while (ch_ctrl != '\r'){
			ch_ctrl = getch();
			if (ch_ctrl == '\b'){
				printf("\b");
				break;
			}
			else if (ch_ctrl != '\r'){
				printf("\a");
			}
		}
		if (ch_ctrl == '\b')
			continue;
		flag = 1;
	}

}

/*****getpass(): getting password*****/
// WRITTEN BY: Behzad Shabani
// CALLING FUNCTION: getpass(pass);

void getpass(char* pass){

	/* function variables */
	char ch;
	int flag = 0, i = 0;

	/* function process*/
	while(flag == 0){
		ch = getch();
		if (ch == '\r'){
			if (i != 0){
				pass[i] = NULL;
				flag = 1;
				continue;
			}
			printf("\a");
			continue;
		}
		else if (ch == '\b'){
			printf("\b");
			i--;
			continue;
		}
		printf("*");
		pass[i] = ch;
		i++;
	}

}

/****** add_std() : adding student into the database by teacher ******/
//WRITTEN BY : Sepehr Safi
//CALLING FUNCTION: add_std();


void add_std(){

	/* Function Variables */
	char* name,*std_num;
	float quiz[3],exercises[5],project[2];
	int m=0,n=0,b=0,v;
	
	/* Function Process */
	printf("\nPlease Enter The Student's Name :");
	gets(name);
	printf("\nStudent's Name Is :");
	puts(name);
	printf("\nPlease Enter The Student's Number :");
	gets(std_num);
	printf("\nStudent's Number Is :");
	puts(std_num);

	do{
		printf("\nEnter The Quiz[%d] point:",m+1);
		scanf("%f",&quiz[m]);
		printf("\nThe Quiz[%d] point Is :%f",m,quiz[m]);
		m++;
	}while(m<3);

	do{
		printf("\nEnter The Exercise Series[%d] point:",n);
		scanf("%f",&exercises[n]);
		printf("\nThe Exercise Series[%d] point Is :%f",n,exercises[n]);
		n++;
	}while(n<5);

	do{
		printf("\nEnter The Project[%d] point:",b);
		scanf("%f",&project[b]);
		printf("\nThe Project[%d] point Is :%f",b,project[b]);
		b++;
	}while(b<2);

}

/****** inf_viewer(): showing each student's information ******/
//WRITTEN BY: Sepehr Safi
//CALLING FUNCTION: inf_viewer();
void inf_viewer(){

	/* Function Variables */
	char* name;
	float quiz[3],exercises[5],project[2];
	int l=0,k=0,h=0,i;
	student* std;

	/* Function Process */
	printf("\nYou're The Student Number[%d]\n", i+1);
	while(l<3){
		printf("\nThe Numbers Of Your Quizes Are:");
		printf("%f",std[i].quiz[l]);
		printf("\n");
		l++;
	}
	while(k<5){
		printf("\nThe Numbers Of Your Exercises Are:");
		printf("%f",std[i].exercises[k]);
		printf("\n");
		k++;
	}
	while(h<2){
		printf("\nThe Numbers Of Your Projects Are:");
		printf("%f",std[i].project[h]);
		printf("\n");
		h++;
	}
	getch();
}

/****** show_list() : show students name 15 by 15 ******/
//WRITTEN BY : Behzad Shabani
//CALLING FUNCTION: show_list();

void show_list(student* std){

	/* Function variables */
	int i = 0, j = 0, flag = 0;
	char cmd;

	/* Function process */
	do{
		while(i < 15 ){
			printf("\n%d.", i + j + 1);
			puts((*std + i + j)-> name);
			i++;
		}
		printf("\nDo you want to continue the list? (Y/N):");
		getcmd(&cmd);
		switch (cmd){
			case 'y':
			case 'Y':
				printf("\n\ncontinuing");
				continue;
			break;
			case 'n':
			case 'N':
				printf("\n\n list ended");
				flag = 1;
			break;
			default:
				printf("\n\n\aUnknown command!");
			break;
		}
		j += 15;
		i = 0;
	}while (flag == 0);

}
and this is the struct.h file:
Code:
/*   struct.h
 
     defining new types, students and teacher, made of structure

     written by: Behzad Shabani
     Improved by: Sepehr Safi
*/



#if !defined(__STRUCT_H)

#define __STRUCT_H


typedef struct student{

	char name[45];
	
	char std_num [9];
	
	float quiz[3];
	
	float exercises[5];
	
	float project[2];

	};


typedef long int teaherpass[9];


#endif
behzad_shabani is offline   Reply With Quote
Old 06-12-2008, 03:16 AM   #2
Registered User
 
Join Date: May 2008
Location: IR, Iran
Posts: 101
if you see other problem in my code please tell and help me.
thanks
behzad_shabani is offline   Reply With Quote
Old 06-12-2008, 03:25 AM   #3
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
Pointers are not storage units.
http://cpwiki.sf.net/A_pointer_on_pointers
And never, never, never EVER use gets.
http://cpwiki.sf.net/Gets
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-12-2008, 03:34 AM   #4
Registered User
 
Join Date: May 2008
Location: IR, Iran
Posts: 101
Quote:
Originally Posted by Elysia View Post
Pointers are not storage units.
http://cpwiki.sf.net/A_pointer_on_pointers
And never, never, never EVER use gets.
http://cpwiki.sf.net/Gets
so what should I do to show a structure member in afunction?
behzad_shabani is offline   Reply With Quote
Old 06-12-2008, 03:38 AM   #5
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
Code:
typedef struct student{
	char name[45];
	char std_num [9];
	float quiz[3];
	float exercises[5];
	float project[2];
};
This is also incorrect. The struct is missing a proper typedef name.

Quote:
Originally Posted by behzad_shabani View Post
so what should I do to show a structure member in afunction?
You haven't made yourself clear. You need to elaborate on that one and fix the previousmentioned errors first.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-12-2008, 03:59 AM   #6
Technical Lead
 
QuantumPete's Avatar
 
Join Date: Aug 2007
Location: London, UK
Posts: 723
Quote:
Originally Posted by behzad_shabani View Post
if you see other problem in my code please tell and help me.
Have you actually tried to compile and run this code? Post specific questions and fix things that we bring up first, before moving onto the next thing.

QuantumPete
__________________
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
QuantumPete is offline   Reply With Quote
Reply

Tags
pointer

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assignment to a structure array member sj999 C Programming 4 05-22-2008 11:13 PM
Drawing Program Max_Payne C++ Programming 21 12-21-2007 05:34 PM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
Zeroing out member arrays in a Structure manofsteel972 C++ Programming 4 03-26-2004 03:50 AM
nightmare - understanding whats going on in a linked list fate C Programming 2 11-28-2003 11:50 AM


All times are GMT -6. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22