can somebody tell me why this isn't creating the file?
can somebody tell me why this isn't creating the file?
Last edited by Sev3r; 06-27-2006 at 01:13 PM.
In these sorts of situations, it's better to use strcpy() instead of copying the string character by character yourself. This will help you to avoid making mistakes like in the above code. This is what you meant to do:Code:for(i = 0; i<= length; i++) { file[i] = *token[2]; *token[2]++; }
Code:char file[length+1]; for(i = 0; i<= length; i++) { file[i] = token[2][i]; }
i keep getting the seg. fault
Last edited by Sev3r; 06-26-2006 at 10:05 PM.
token is an array of what I assume are strings. You can index into a string using [].token is not a 2D array
But if it helps you sleep better at night, do this instead:
Code:file[i] = token[2] + i;
Are you sure the data that is getting passed to the function is valid? Does token[2] point to a NULL terminated string?i keep getting the seg. fault
The input is tokenized with strtok() with the space delimeter
token [2] is the 3rd token in the input.
so it does not have the '\0' im guessing.
does it need it?
Are you sure you used strtok() correctly?
And to answer your question: yes, token[2] needs to be null terminated. If it isn't thenwill give you a seg fault.Code:int length = strlen(token[2]);
check your pm for full program
ah success!
forget the \n as a delimeter in my other function