I'm sure this is a beginner's mistake, but exactly how should it be done?
I made this example code to illustrate my question:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Right(char* In, char* Out, int Position){
Out=&In[strlen(In)-Position];
return 0;
}
int main(int argc, char *argv[])
{
char *a="Hello, world!", *b;
puts(a);
Right(a,b,3); // Total failure…
puts(b);
b=&a[strlen(a)-3]; // Works
puts(b);
return 0;
}
Well, I guess the code explains it all. I want b to be the last three characters of a using a function called ”Right”.
Doing exactly the same thing without the function involved works fine. I just let b point to the third last character of a.
Why does the function not work?