AerisNeo AerisNeo - 4 years ago 77
C Question

getting a token between two different delimiters

I need to get the last character from a string. Say the string looks like this:


I was thinking I could use strlen and then just subtract by 1 to get the 5. I have tried a bunch of different ways but none of them work. That's the way I have the way I think it should look or do, but I know that its not working. Any suggestions? This is sort of my code-pseudocode. I know it doesn't work for a variety of reasons but its sort of the flow I had in mind.

len = strlen(Input);
Position = Input[len - 1];
strcpy(value, Input[Position]);

Answer Source
 len = strlen(Input); //ok

Here you are going wrong . Putting a character into integer is incorrect. You need this.

 Position = Input[len - 1]; //incorrect

Do it as

 Position = strlen(Input) - 1 //correct

 strcpy(value, &Input[Position]);//ok
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download