Skip to content

Instantly share code, notes, and snippets.

@iKlotho
Last active August 29, 2015 14:12
Show Gist options
  • Save iKlotho/5df2e5609e52fb6f7ee9 to your computer and use it in GitHub Desktop.
Save iKlotho/5df2e5609e52fb6f7ee9 to your computer and use it in GitHub Desktop.
void kullanici_ekle()
{
system("cls");
first_memur();
first_kullanici();
user_information();
Sleep(3000);
system("cls");
struct kullanici users;
FILE *add_user;
fopen_s(&add_user, "user_information.dat", "a");
if (add_user == NULL)
printf("user_information.dat acilamadi.");
else
{
printf("Isim giriniz : ");
gets_s(users.ad);
_flushall();
printf("Soyisim giriniz : ");
gets_s(users.soyad);
_flushall();
printf("TC-Kimlik giriniz : ");
gets_s(users.tckimlik);
_flushall();
printf("Telefon giriniz : ");
gets_s(users.telefon);
_flushall();
printf("E-Posta giriniz : ");
gets_s(users.eposta);
_flushall();
printf("Kullanici adini giriniz : ");
gets_s(users.kullanici_adi);
_flushall();
FILE *ch;
fopen_s(&ch, "adminsifre.dat", "r");
int lines_allocated = 1000;
int max_line_len = 150;
int i;
char **words = (char **)malloc(sizeof(char*)*lines_allocated);
for (i = 0; 1; i++)
{
int j;
if (i >= lines_allocated)
{
int new_size;
new_size = lines_allocated * 2;
words = (char **)realloc(words, sizeof(char*)*new_size);
if (words == NULL)
{
fprintf(stderr, "Out of memory.\n");
exit(3);
}
lines_allocated = new_size;
}
words[i] = (char*)malloc(max_line_len);
if (words[i] == NULL)
{
fprintf(stderr, "Out of memory (3).\n");
exit(4);
}
if (fgets(words[i], max_line_len - 1, ch) == NULL)
break;
for (j = strlen(words[i]) - 1; j >= 0 && (words[i][j] == '\n' || words[i][j] == '\r'); j--)
words[i][j] = '\0';
}
for (int k = 3; k < sizeof(words); k = k + 2){
if (strcmp(users.kullanici_adi, words[0]) == 0){
printf("\t Gecersiz Kullanici Adi !!");
break;
}
else if (strcmp(users.kullanici_adi, words[k]) == 0){
printf("\t Gecersiz Kullanici Adi !!");
break;
}
else{
printf("Sifrenizi giriniz : ");
gets_s(users.sifre);
_flushall();
do{
printf("Yetki turunu giriniz(Admin = a,Memur = m, Kullanici = k) : ");
users.yetki_turu = getchar();
_flushall();
} while (users.yetki_turu != 97 && users.yetki_turu != 107 && users.yetki_turu != 109);
printf("Il : ");
gets_s(users.address.il);
_flushall();
printf("İlce : ");
gets_s(users.address.ilce);
_flushall();
printf("Cadde : ");
gets_s(users.address.cadde);
_flushall();
printf("Mahalle : ");
gets_s(users.address.mahalle);
_flushall();
printf("Sokak : ");
gets_s(users.address.sokak);
_flushall();
printf("Apartman : ");
gets_s(users.address.apartman);
_flushall();
printf("No : ");
gets_s(users.address.no);
_flushall();
fprintf(add_user, "%s\t%s\t%s\t%s\t%s\t%s\t%c\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", users.ad, users.soyad, users.tckimlik, users.telefon, users.eposta, users.kullanici_adi,
users.yetki_turu, users.address.il, users.address.ilce, users.address.cadde, users.address.mahalle, users.address.sokak, users.address.apartman, users.address.no);
if (users.yetki_turu == 'a')
{
fopen_s(&add_user, "adminsifre.dat", "a");
fprintf(add_user, "\n%s\n%s", users.kullanici_adi, users.sifre);
}
else if (users.yetki_turu == 'm')
{
fopen_s(&add_user, "memursifre.dat", "a");
fprintf(add_user, "\n%s\n%s", users.kullanici_adi, users.sifre);
}
else if (users.yetki_turu == 'k')
{
fopen_s(&add_user, "kullanicisifre.dat", "a");
fprintf(add_user, "\n%s\n%s", users.kullanici_adi, users.sifre);
}
break;
}
}
}
fclose(add_user);
fclose(ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment