strtok corrupt the passed data?
Hi all,
Calling the function is_macid_valid(char * macid), modifies the macid pointer hence unavailiable for further, i think problem lyis using strtok, can i have suggestion , so as to retain the macid value after calling is_macid_valid().. Thanks in advance int IS_MACID_VALID(char * macid) { int i = 0, len = 0; char *ptr; len = strlen(macid); ptr = strtok(macid, ":"); while(ptr) { ptr = strtok(NULL, ":"); i++; } return (((len == 17) && (i==6))? 0 : -1); } //return((i==6)? 0 : 1);\ //if(i==6) printf("valid = %d\n", i);\ //else printf("Invalid=%d\n", i); \ main() { char san[24]="00:11:22:33:44:55"; printf("Min strlen = %d\n", strlen(san)); printf("Macid Before = %s\n", san); printf("GG=%d\n",IS_MACID_VALID(san)); printf("After Macid = %s\n", san); return 0; |
From the man page
Quote:
PS There is a dedicated programming section at LQ. |
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
All times are GMT -5. The time now is 04:22 AM. |