Pershendetje,
Jam nje student i Inxhinierise Informatike ne Universitetin Politeknik te Tiranes.Doja te me ndihmonit nqs mundeshit dhe nqs keni kohe me nje detyre kursi te zhvilluar ne gjuhen C te cilen une e kam zhvilluar por po me lindin shume pyetje.Kjo eshte detyra e kursit:

Tema: Libri i kontakteve
Tė ndėrtohet njė program nė gjuhėn C, i cili ruan nė njė dokument tekst listėn e kontakteve/personave. Ēdo kontakt duhet tė ruajė informacion pėr: Emri, Mbiemri, Lista e Email (mund te kete disa adresa), lista e numrave te telefonave (mund tė ketė disa, psh. nr.zyre, celular etj). Implementoni njė strukturė tė pėrshtatshme pėr tė ruajtur kėto tė informacione nė njė dokument teskt.
Programi juaj duhet tė:
1. Afishojė nė mėnyrė sa mė efiēente listėn e renditur tė kontakteve.
2. Afishojė nė mėnyrė sa mė efiēente tė gjithė kontaktet tė cilave u fillon emri ose mbiemri me njė bashkėsi karakteresh tė dhėna nga pėrdoruesi.
3. Shtojė nė mėnyrė efiēente njė kontakt tė ri.
4. Modifikojė njė kontakt ekzistues.
5. Fshijė njė ose disa kontakte njėherėsh.
6. Afishojė 10 kontaktet e preferuara (kontakte tė preferuara janė ato tė janė kėrkuar mė shpesh nga pėrdoruesit).
Sugjerohet tė pėrdorni njė nga strukturat e tė dhėnave tė studiuara gjatė lėndės pėr tė mbajtur listėn e kontakteve nė run-time tė programit.
Kėrkohet zgjidhje me performancė optimale.


Per kete detyre kam bere kete zgjidhje me ane te struktures se listave :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *data;
struct node* L = NULL;
struct nodeMail* M = NULL;
struct nodeNr* N = NULL;

struct nodeMail {
char email[20];
nodeMail* next;
};
struct nodeNr {
char numri[10];
nodeNr* next;
};
struct node {
char emri[10], mbiemri[10];
nodeMail* email=NULL;
nodeNr* numri=NULL;
int r, plq;
node* next;
};
int meVogel (struct node* a, struct node* b) {
if (strcmp(a->emri, b->emri)<0) // >0 => a<b
{
//|| (strcmp(a->emri, b->emri)==0 && strcmp(a->mbiemri, b->mbiemri)>0)
printf("%s < %s\n", a->emri, b->emri);
} return 1;
printf("%s > %s\n", a->emri, b->emri);
return 0;
}
void printMail (struct nodeMail* p) {
if (p == NULL)
return;
printf("%s\n", p->email);
printMail(p->next);
}
void printNr (struct nodeNr* p) {
if (p == NULL)
return;
printf("%s\n", p->numri);
printNr (p->next);
}
void printoData (struct node* p) {
if (p == NULL)
return;
printf("%d - %s %s\n", p->r, p->emri, p->mbiemri);
printf("\ne-Mail:\n-------\n");
printMail(p->email);
printf("\nTelefon:\n--------\n");
printNr(p->numri);
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~\n");
printoData (p->next);
}
void printoPlq (struct node* p, int i) {
if (p == NULL || i==10)
return;
printf("%d - %s %s\n", p->r, p->emri, p->mbiemri);
printf("Kerkime: %d", p->plq);
/* printf("\ne-Mail:\n-------\n");
printMail(p->email);
printf("\nTelefon:\n--------\n");
printNr(p->numri); */
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~\n");
printoPlq (p->next, i+1);
}
struct node* shto (node* head, char emri[], char mbiemri[], nodeMail* email, nodeNr* numri, int i) {
node *temp = (struct node*) malloc (sizeof (struct node));
strcpy(temp->emri, emri);
strcpy(temp->mbiemri, mbiemri);
temp->email = email;
temp->numri = numri;
temp->r = i;
temp->plq = 0;
temp->next = NULL;
if (head == NULL)
head = temp;
else {
node* temp1 = head;
while (temp1->next != NULL)
temp1 = temp1->next;
temp1->next = temp;
}
return head;
}
struct nodeMail* shtoMail (nodeMail* head, char email[]) {
nodeMail *temp = (struct nodeMail*) malloc (sizeof (struct nodeMail));
strcpy(temp->email, email);
temp->next = NULL;
if (head == NULL)
head = temp;
else
{
nodeMail* temp1 = head;
while (temp1->next != NULL)
temp1 = temp1->next;
temp1->next = temp;
}
return head;
}
struct nodeNr* shtoNr (nodeNr* head, char numri[]) {
nodeNr *temp = (struct nodeNr*) malloc (sizeof (struct nodeNr));
strcpy(temp->numri, numri);
temp->next = NULL;
if (head == NULL)
head = temp;
else
{
nodeNr* temp1 = head;
while (temp1->next != NULL)
temp1 = temp1->next;
temp1->next = temp;
}
return head;
}
void lexoData () {
char emri[10], mbiemri[10], email[20], numri[10];
int i=1;

if ((data=fopen("data.txt", "r"))==NULL) {
data=fopen("data.txt", "w");
fclose(data);
data=fopen("data.txt", "w");
}
while (!feof(data)) {
fscanf(data, "%s %s", emri, mbiemri);

fscanf(data, "%s", email);
while (strcmp(email, ";")!=0) {
M = shtoMail(M, email);
fscanf(data, "%s", email);
}

fscanf(data, "%s", numri);
while (strcmp(numri, "<")!=0) {
N = shtoNr(N, numri);
fscanf(data, "%s", numri);
}

L = shto(L, emri, mbiemri, M, N, i++);
M=NULL; N=NULL;
}
fclose(data);
}
void ruajData (node* head) {
data=fopen("data.txt", "w");
nodeMail* h1; nodeNr* h2;
while (head!=NULL) {
fprintf(data, "%s %s ", head->emri, head->mbiemri);
h1 = head->email;
while (h1!=NULL) {
fprintf(data, "%s ", h1->email);
h1=h1->next;
}
fprintf(data, "; ");
h2 = head->numri;
while (h2!=NULL) {
fprintf(data, "%s ", h2->numri);
h2=h2->next;
}
fprintf(data, "<");
head = head->next;
if (head!=NULL)
fprintf(data, "\n");
}
fclose(data);
}
void kerko (node* head, char x[]) {
int i=1;
while (head!=NULL) {
if (strstr(head->emri, x)!=NULL || strstr(head->mbiemri, x)!=NULL) {
head->plq++;
printf("%d - %s %s\n", i++, head->emri, head->mbiemri);
printf("\ne-Mail:\n-------\n");
printMail(head->email);
printf("\nTelefon:\n--------\n");
printNr(head->numri);
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~\n");
}
head = head->next;
}
}
void edito (node* head, int x) {
int i=1;
char c[20];
while (i<x) {
head = head->next;
i++;
}
printf("%s %s\n", head->emri, head->mbiemri);
printMail (head->email);
printNr (head->numri);
printf("\nEmri i ri: ");
scanf("%s", head->emri);
printf("Mbiemri i ri: ");
scanf("%s", head->mbiemri);
/* printf("Email: ");
scanf("%s", c);
while (strcmp(c, ";")!=0) {
shtoMail(head->email, c);
printf("Email: ");
scanf("%s", c);
}
printf("Numri: ");
scanf("%s", c);
while (strcmp(c, ";")!=0) {
shtoNr (head->numri, c);
printf("Numri: ");
scanf("%s", c);
} */
}
struct node* fshi (node* head, int x[]) {
int i=1;
node* p = head;
node* q = head->next;
while (x[i]!='\0') {
while (q!=NULL) {
if (q->r == x[i]) {
p->next = q->next;
free(q);
q = p->next;
break;
}
p = q;
q = q->next;
}
i++;
}
if (head->r == x[0]){
p = head->next;
free(head);
return p;
}
return head;
}
void renditPlq (node* p) {
node* q;
node* min;
node *head = (struct node*) malloc (sizeof (struct node));
head->next = L;
p = head;

while (p->next->next!=NULL)
{
min = p;
q = p->next;
while (q->next!=NULL)
{
if (min->next->plq < q->next->plq)
min = q;
q = q->next;
}
node* a = p->next;
p->next = min->next;
min->next = a;
node* b = a->next;
a->next = p->next->next;
p->next->next = b;
p = p->next;
}
L = head->next;
}
void rendit (node* p) {
node* q;
node* min;
node *head = (struct node*) malloc (sizeof (struct node));
head->next = L;
p = head;

while (p->next->next!=NULL)
{
min = p;
q = p->next;
while (q->next!=NULL)
{
if (strcmp(min->next->emri, q->next->emri)==1|| (strcmp(min->next->emri, q->next->emri)==0 && strcmp(min->next->mbiemri, q->next->mbiemri)==1))
min = q;
q = q->next;
}
node* a = p->next;
p->next = min->next;
min->next = a;
node* b = a->next;
a->next = p->next->next;
p->next->next = b;
p = p->next;
}
L = head->next;
}
int main() {
char search[20];
char a[10], b[10];
int ndr, vfshi[10], i=0, e, plq[10];
node* p = L;

lexoData();
rendit(L);
printf("* * * LIBRI I KONTAKTEVE * * *\n\n");
do {
printf("1 - Shiko kontaktet\n");
printf("2 - Kerko kontakt\n");
printf("3 - Shto kontakt\n");
printf("4 - Modifiko kontaktet\n");
printf("5 - Fshi kontakte\n");
printf("6 - Te preferuarit\n");
printf("7 - Dil\n");
printf("Ekzekuto: ");
scanf("%d", &e);
printf("\n\n");

if (e == 1) { // sh
printoData(L);
}
else if (e == 2) { // ke
printf("Kerko: ");
scanf("%s", search);
printf("\n\n");
kerko (L, search);
}
else if (e == 3) { // s
while (p->next != NULL)
p = p->next;
node *temp = (struct node*) malloc (sizeof (struct node));
printf("Emri: ");
scanf("%s", temp->emri);
printf("Mbiemri: ");
scanf("%s", temp->mbiemri);
printf("Email: ");
do {
scanf("%s", search);
if (strcmp(search, ";")!=0)
shtoMail(temp->email, search);
} while ((search, ";")!=0);
printf("Numri: ");
do {
scanf("%s", search);
if (strcmp(search, ";")!=0)
shtoNr (temp->numri, search);
} while (strcmp(search, ";")!=0);
temp->next = NULL;
p->next = temp;
}
else if (e == 4) { // modif
printf("Ndrysho: ");
scanf("%d", &ndr);
edito(L, ndr);
rendit(L);
}
else if (e == 5) { // f
printf("Fshi: ");
do {
scanf("%d", &vfshi[i]);
} while (vfshi[i++]!=0);
vfshi[i]='\0';
L = fshi(L, vfshi);
}
else if (e == 6) { // te preferu
renditPlq(L);
printoPlq(L, 0);
rendit(L);
}
else { //
ruajData(L);
break;
}
} while (e>0 && e<8);
return 0;
}


PROBLEMI ESHTE SE KUR E EKZEKUTOJ ME NXJERR NJE GABIM DHE ME CON NE CIKEL TE PAFUNDEM.JU LUTEM ME NDIHMONI ME RREGULLIMIN E KETIJ GABIMI.GJITHASHTU DO DOJA TE ME SHPJEGONIT NDNJ MENYRE TJETER SI TA REDUKTOJ KOMPLEKSITETIN.JU FLM