Hello. I want to edit a .txt file and I have no idea of how to do it - this is what I have come up with so far. With the .txt file reading this:
PHP Code:
Mary;May;12 Good Lane;02 6889 2456;maryblossom@yahoo.com;4567 7956 4562 4568;12/17;124;5559864582456;010134;David;Bowie;In Space;09000000;bowie@space.com;0000587945642134;10/99;458;795;010376;Mr.;Tree;The Jungle; 12456;tree@jungle.com;46546464;65/12;656;5683655;010588;
When I run it, it prompts me to enter the new name but nothing happens.
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
typedef struct{
char fname[32];
char lname[32];
char address [64];
char phone [16];
char email [64];
char credit_num[32];
char credit_expiry[16];
char credit_bsb[4];
char licence_num[32];
int ID;
}customer;
int main(){
customer custData[128];
int ch;
char surname[32];
char fname[32];
FILE *cust;
char address[64];
char num[16];
char mail[64];
char crednum[32];
char expiry[16];
char bsb[4];
char licnum[32];
char line[18];
char *item;
int i = 0;
int reccount = 0;
int ID;
int a;
char newName[28];
int no;
cust = fopen("customer.txt", "r");
while(fgets(line,126,cust))
{
//for copying strings
item = strtok(line, ";");
strcpy(custData[reccount].fname, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].lname, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].address, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].phone, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].email, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].credit_num, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].credit_expiry, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].credit_bsb, item);
item = strtok(NULL, ";");
strcpy(custData[reccount].licence_num, item);
item = strtok(NULL, ";");
custData[reccount].ID = atoi(item);
reccount++;
}
fclose(cust);
cust = fopen("customer.txt", "a");
printf("1 - Find with customer ID");
printf("\n2 - Find with customer name");
scanf("%d", &ch);
switch(ch){
case 1:
printf("Enter customer ID>");
scanf("%d", &ID);
for(i=0;i<126;i++){
if(ID == custData[i].ID){
printf("\n1 - Change first name\n2 - Change surname\n3 - Change address\n4 - Change phone\n5 - Change phone\n6 - Change credit card number\n7 - Change credit card expiry\n8 - Change credit card BSB\n9 - Change licence number\n");
scanf("%d", &no);
if(no==1){
printf("Enter new first name>");
scanf("%s", custData[i].fname);
fprintf(cust, "%s", fname);
}
else if(no==2){
}
}
}
/*
case 2:
printf("Enter customer name>");
fgets(name, 62, stdin);
}
*/
}
fclose(cust);
}
any hints or pointers are appreciated.