I'm creating a sales project for a specific product in c. What happens is that each customer is required to register to have a customer number, but I have a problem because the program manages the number, but when it goes to save it in the txt file, it doesn't give the correct one. However I'm having another problem with the client's name, if I write the full name it gives an error. How can I solve these problems? Thanks
This is my code:
#include <stdlib.h>
#include <stdio.h>
typedef struct client CLIENT;
struct client {
char name[80];
char country[10];
int tin;
};
void createprofile() {
char tin_present;
int i;
FILE* bd;
bd = fopen("bd.txt", "a+");
CLIENT c;
printf("\t *** Create customer profile *** \n");
printf("Client code: ");
for (i = 0; i < 1; i++) {
printf("%d\n ", rand() % 1000000);
}
printf("Type your name: ");
scanf("%s", &c.name);
printf("TIN present?? ");
scanf("%s", &tin_present);
if (tin_present == 's' || tin_present == 'S') {
while (1) {
printf("\n\tEnter your TIN: ");
scanf("%d", &c.tin);
if (c.tin >= 999999999) {
printf("\tNumber with more than 9 digits is not allowed. Please try again.");
} else if (c.tin <= 99999999) {
printf("\tNumber with less than 9 digits is not allowed. Please try again.");
} else
break;
}
printf("\tValid.\n");
} else {
printf("TIN not entered\n");
}
printf("What is your country? ");
scanf("%s", &c.country);
fprintf(bd, "code: %d | name: %s | tin: %i | country: %s \n", c.name, c.tin, c.country);
fclose(bd);
}