As no one have answered me i will post it again if someone could help i would appreciate... PLEASE!!! My brain is already melting :/
I know it's not a simple question but i really can't understand what is happening :/
I'm having a problem with a function... everything goes ok till it returns the result because the string get somehow "corrupted"... i have searched for errors but i really didn't find it... it's a complex code, with structs and pointers and but i will copy and paste what i think it's necessary to understan it... If someone could help the error occurs in the line "TF = GetToken();" in the function LTEIns();
the functions ImpErr(); and ImpErrS(); just print error messages and aren't necessary and for that i didn't post them. The functions VerChFo(); and VerChNo just verify if the chars are valid characters... and if there is some /**/ in the middle it's just things i had changed trying to fix it/
Thanks and sorry for so much codeCode:#define INTGR 1 #define FLT 2 #define STRG 3 #define TOK 4 #define TRUE 1 #define FALSE 0 #define ENTER 13 #define MAXF 10 #define MAXS 30 #define NOME 5 #define FONE 6 typedef struct tokelemento { int ttelem; char *tpselem; }*TOKELEM; typedef struct tokens { TOKELEM nomelem; TOKELEM fonelem; }*TOKEN; typedef struct elemento { int telem; union { int ielem; float felem; char *pselem; TOKEN toelem; } elem; } *PLISTELEM; typedef struct lnodo { PLISTELEM litem; struct lnodo *next; } *PLIST; char VerChNo (char *c) { while ( ((*c!= ' ') && (*c!= ENTER) && (*c!='"')) && ((*c < 'A') || (*c > 'Z')) && ( (*c < 'a') || (*c > 'z'))) { if (*c == 0) { *c = getch(); if (*c==10) return ENTER; fflush(stdin); printf ("\b"); ImpErr(); *c = getche(); } else sound(362); delay (500); nosound( ); printf ("\b"); textcolor(0); putch (219); textcolor(15); printf ("\b"); ImpErr(); *c = getche(); } if ((*c>= 'a') && (*c<='z')) *c = toupper(*c); return *c; } char VerChFo (char *c) { while ( ((*c!= ' ') && (*c!= ENTER)) && ( (*c < '0') || (*c > '9')) && (*c != '-')) { if (*c == 0) { *c = getch(); if (*c==10) return ENTER; fflush(stdin); printf ("\b"); ImpErr(); *c = getche(); } else sound(362); delay (500); nosound( ); printf ("\b"); textcolor(0); putch (219); textcolor(15); printf ("\b"); ImpErr(); *c = getche(); } return *c; } TOKELEM GetToken (void) { char c; TOKELEM tok=NULL; char S[MAXS], F[MAXF]; int i = 0; float fl; c = getche(); while ( c == ' ') c=getche(); while ( (c != ' ' ) && (c!= ENTER) ){ tok = malloc (sizeof(struct tokelemento)); if (c=='"') { c=getche(); VerChNo(&c); while ( c!='"'){ S[i]=c; i++; c=getche(); VerChNo(&c); if (i==MAXS-2) { c = '"'; ImpErrS(S); } } S[i]='\0'; tok->ttelem = NOME; tok->tpselem = S; return tok; } else if (c>='0'&& c<='9'){ do { while ( (c != ' ' ) && (c!= ENTER) ){ F[i]=c; i++; c=getche(); VerChFo(&c); if (i==(MAXF-1) c=' '; } F[i]='\0'; tok->ttelem = FONE; /* strcpy(tok->tpselem, F);*/ tok->tpselem = *F; if ((strstr(tok->tpselem,"-") == NULL) || (strlen(F)<8) || (strlen(F)>10)) { printf ("\n Erro de inserçao do telefone!"); printf ("\n Insira novamente o numero do telefone no formato nnnn-nnnn\n "); c = getche(); VerChFo(&c); } } while (( strstr(tok->tpselem,"-") == NULL ) || (strlen(F)<8) || (strlen(F)>10)); return tok; } else { printf ("\n Erro de inserção!!! Insira o nome entre \"s e separe-o do telefone por espaço"); c=getche(); } } tok = NULL; return tok; } PLISTELEM LTEIns (void) { int TL = TOK; PLISTELEM LE; TOKELEM TN, TF; LE = malloc (sizeof(struct elemento)); LE->telem = TL; fflush(stdin); while ( 1 ){ TN = GetToken(); if (TN->ttelem == NOME) { LE->elem.toelem->nomelem = TN; TF = GetToken(); while ( TF->ttelem != FONE ) { printf ("\n Erro ao inserir o número do telefone!"); printf ("\n Insira o número do telefone no formato nnnn-nnnn:\n\n "); TF = GetToken(); } LE->elem.toelem->fonelem = TF; return LE; } else printf ("\nErro ao inserir o nome!!!"); printf ("Insira os dados no formato \"nome\" nnnn-nnnn: \n\n "); } }
Frigga



LinkBack URL
About LinkBacks
/


