Originally Posted by
grumpy
Try explaining, first, what input, pinput, BUF, pct, pctcounter, and firstName are. We're not mindreaders, you know.
Then explain what you expect that code to achieve and, more importantly, why you expect it will even come close to achieving it.
As to why it is crashing, that is easy. You are molesting pointers. The problem is, you haven't provided enough information so that any mere mortal (without ability to read your mind) can work out what pointers are being molested.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define BUFF 120
#define SIZE 9
#define STND 20
#define CLIENTS 50
struct client
{
char firstName[STND];
char lastName[STND];
char ID[STND];
char email[STND];
float funds;
// float wager;
}typedef client;
// FUNCTIONS <<<<<<<<<<<<<>>>>>>>>><<<<<<>>>>><<<>>><<>><<>>><<>><><
void menu();
char getct(client *,int *);
char checkNameTypeA(char *);
void testdisplay(struct client *pct);
int main()
{
client ct[CLIENTS];
client *pct = &ct[0];
int clientCounter = 0;
int *pctcounter = &clientCounter;
menu();
int x = 0;
while(x != 4)
{
printf("enter selection : ");
scanf("%d", &x);
switch(x)
{
case 1:
getct(pct, pctcounter);
break;
case 2:
break;
case 3:
break;
case 4:
return EXIT_SUCCESS;
break;
}
}
return EXIT_SUCCESS;
}
//************************************************************************************
void menu()
{
printf("***************************************************************************\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("**************WELCOME************VIRTUAL***********************************\n");
printf("************************TO********************CASINO***********************\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("***************************************************************************\n\n\n");
printf("---Register #1\n\n");
printf("---ATM Machine #2\n\n");
printf("---Play #3\n\n");
printf("---QUIT #4\n\n");
}
//************************************************************************************
//***************************************************************************
/*void displaytest(client *pct)
{
printf("Student ID: %s\n", pct->firstName );
printf("Student Phone: %s\n", pct->lastName);
printf("Student GPA: %s\n", pct->ID);
}*/
//****************************************************************************
char getct(client * pct, int *pctcounter)
{
char * input[BUFF];
char *pinput = NULL;
// float funds = 0;
// float wager= 0;
// fflush(stdin);
fflush(stdin);
printf("Enter your firstname: ");
pinput = fgets(input, BUFF, stdin);
strncpy((pct + *pctcounter-1) ->firstName,pinput , strlen(pinput) - 1);
memset(&input, 0, sizeof(input));
printf("Enter your lastname: ");
pinput = fgets(input, BUFF, stdin);
strncpy(pinput,(pct + *pctcounter-1) ->lastName , strlen(pinput) - 1);
memset(&input,0, sizeof(input));
printf("Enter your email: ");
pinput = fgets(input, BUFF, stdin);
strncpy((pct + *pctcounter-1) ->email ,pinput , strlen(pinput) - 1);
memset(&input,0, sizeof(input));
//***************************************************** I.D GEN
srand(time(NULL));
int r, id1, id2;
do{
r = rand();
}while(r>100);
do {
id1 = rand() / r ;
}while(id1<1000 || id1 >10000);
do {
id2 = rand() / 2 - r;
}while(id2<10000 || id2 >100000);
printf("Your I.D is: %d-%d \n", id1, id2);
printf("Please retype I.D to comfirm: \n");
pinput = fgets(input, BUFF, stdin);
strncpy(pinput ,(pct + *pctcounter-1) ->ID , strlen(pinput) - 1);
memset(&input,0, sizeof(input));
//****************
//*****************************************************
system("cls");
printf("-------------------------------\n");
printf("client lastname\t: %s\n", (pct + *pctcounter-1)->firstName);
printf("client lastname\t: %s\n", (pct + *pctcounter-1)-> lastName);
printf("client emai\t: %s\n", (pct + *pctcounter-1)-> email);
printf("client ID\t: %s\n", (pct + *pctcounter-1)-> ID);
printf("client funds\t: %.02f\n", (pct + *pctcounter-1)-> funds);
return pinput;
}
//****************************************************************
char checkNameTypeA(char *pinput)
{
int i = 0;
for( i = 0; i < strlen(pinput) - 1; i++)
{
if(!isalpha(*(pinput+i)))
{
return 0;
}
}
return 1;
}
//******************************************
int checkCurr(char *pinput)
{
int i = 0;
int isNotVal=0;
for(i=strlen(pinput) - 1;i>0 - 1; i--)
{
if(i==strlen(pinput)-4)
{
if((int)(pinput+i)==46)
{
}
else
{
isNotVal = 1;
}
}else{
if((int)(pinput+i)>=48&&(int)(pinput+i)<=57)
{
}
else
isNotVal = 1;
}
}
return isNotVal;
}
I would simply like it to accept the info provided in the fields and i still haven't exactly worked out how to store the different instances of the client struct. I suppose a separate array. I started on it but I am lost in my own code at this point... Again sorry for the lack of clarity.