This is an unfinished file name immigration.c
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "structure.h"
#include "modifyImmigration.h"
int main(int argc,char* argv[])
{
int status = 0;
char buffer[64];
char codeString[64];
DATA_T person[100];
int check;
char *newValue;
int index;
int modify;
while(status != 6)
{
printf("\n\t\t =========================================\n");
printf("\n\t\t\tWelcome to Immigration Database!!\n\n");
printf("\t\t =========================================\n");
printf("\t\t\t Choose what you want to do:\n");
printf("\t\t =========================================\n\n");
printf("\t\t\t 1)Display all records\n");
printf("\t\t\t 2)Search an existing record\n");
printf("\t\t\t 3)Add a new record\n");
printf("\t\t\t 4)Modify an existing record\n");
printf("\t\t\t 5)Delete an existing record\n");
printf("\t\t\t 6)Exit the program\n");
printf("\n\t\t =========================================\n");
printf("\n\t\t Press 1,2,3,4,5 or 6: ");
fgets(buffer,64,stdin);
sscanf(buffer,"%d",&status);
if(status == 1)
{
}
else if(status == 2)
{
}
else if(status == 3)
{
}
else if(status == 4)
{
Edit(argc, argv, newValue, index, modify, person);
}
else if(status == 5)
{
}
else if(status == 6)
{
printf("\n\n\t\t =========================================");
printf("\n\t\t Thank you for using our program :)");
printf("\n\t\t =========================================");
exit(0);
}
else
{
printf("\nError! Please type in the number between 1 to 6.\n");
}
}
}
This is modifyImmigration.c
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "structure.h"
void Edit(int argc, char* argv[], char *newValue, int index, int modify, DATA_T person[100])
{
char* inputFile; /*Pointer inputFile*/
char* outputFile; /*Pointer outputFile*/
char inputBuffer[128];
int i = 0;
int j = 0;
int line = 0;
FILE* pInfile = NULL; /*Set pInfile to be NULL*/
FILE* pOutfile = NULL; /*Set pOutfile to be NULL*/
/*Copy files from arguement array to local variables*/
inputFile = strdup(argv[1]);
outputFile = strdup(argv[1]);
/*Check arguement to make sure that we have the right number. If not,print error message*/
if(argc != 2)
{
printf("Error, You do not supply the correct arguments\n");
exit(1);
}
/*Check to make sure that inputFile or outputFile is not NULL. If it is. print error message*/
if((inputFile == NULL) || (outputFile == NULL))
{
printf("Error, Memory allocation error in strdup\n");
exit(1);
}
/*Open input file*/
pInfile = fopen("person.txt","r");
/*Check that the open succeeded, If not,print error message*/
if(pInfile == NULL)
{
printf("Error, can not open file\n");
}
else
{
/*change to be stored in buffer*/
while(fgets(inputBuffer,128,pInfile) != NULL)
{
sscanf(inputBuffer, "%s %s %s %s %s %s %s",person[i].passportID, person[i].firstName,
person[i].lastName, person[i].expireDate, person[i].entryDate, person[i].exitDate,
person[i].visaType);
i++;
}
line = i;
}
fclose(pInfile);
printf("Which item do you need to modify?\n");
printf("press 1 - Modify Firstname\n");
printf("press 2 - Modify Lastname\n");
printf("press 3 - Modify Passport expiration date\n");
printf("press 4 - Modify Date of last entry into Thailand\n");
printf("press 5 - Modify Date of last exit from Thailand\n");
printf("Which item do you need to modify: ");
fgets(inputBuffer,128,stdin);
sscanf(inputBuffer,"%d",&modify);
while((modify <= 0) || (modify >= 6))
{
printf("Sorry, You have to press 1,2,3,4, or 5. Try again");
printf("Which item do you need to modify: ");
fgets(inputBuffer,128,stdin);
sscanf(inputBuffer,"%d",&modify);
}
switch(modify)
{
case 1: /*name*/
strcpy(person[index].firstName, newValue);
break;
case 2: /*lastname*/
strcpy(person[index].lastName, newValue);
break;
case 3: /*date 1*/
strcpy(person[index].expireDate, newValue);
break;
case 4: /*date 2*/
strcpy(person[index].entryDate, newValue);
break;
case 5: /*date 3*/
strcpy(person[index].exitDate, newValue);
break;
case 6: /*TypePas*/
strcpy(person[index].visaType, newValue);
break;
}
pOutfile = fopen("person.txt","w");
/*Check to make sure that inputFile or outputFile is not NULL. If it is. print error message*/
if((inputFile == NULL) || (outputFile == NULL))
{
printf("Error, Memory allocation error in strdup\n");
exit(1);
}
for(j = 0; j < line; j++)
{
fprintf(pOutfile,"%s %s %s %s %s %s %s\n",person[j].passportID, person[j].firstName,
person[j].lastName, person[j].expireDate, person[j].entryDate, person[j].exitDate,
person[j].visaType);
}
fclose(pOutfile);
}
This is modifyImmigration.h
Code:
void Edit(int argc, char* argv[], char *newValue, int index, int modify, DATA_T person[100]);
and this is structure.h
Code:
typedef struct
{
char passportID[16]; /* Passport ID of the user */
char firstName[30]; /* First name of the user */
char lastName[30]; /* Last name of the user */
char expireDate[10]; /* Expiration date of the passport */
char entryDate[10]; /* Date of last entry into Thailand */
char exitDate[10]; /* Date of last exit from Thailand */
char visaType[30]; /* Type of visa */
} DATA_T;
Why is there an error: undefine reference to '_Edit'
Thank you for your help