[Question]
  [
## Introduction
In the error outputs of some languages such as Java, a **pointer** is shown to give the programmer an idea of exactly where the error went wrong.
Take [this example](http://ideone.com/jd94Vy) on Ideone: 
```
Main.java:12: error: ';' expected
    Invalid Java!
                ^
```
Notice the caret shows where the invalid code is?
## Challenge
Your challenge is: given number **N** and string **S**, place a pointer on the **N**th character in **S**.
## Examples
**Input**: `2, "Lorem ipsum, dollar sit amet."`
**Output**:
```
Lorem ipsum, dollar sit amet.
 ^
```
## Rules
* Input is received via STDIN or function parameters
* Output is printed out to the console or `return`ed
* Trailing new lines, spaces etc are allowed in the output
* The pointer character **must** be a **^** caret and **must be on a new line.**
* This is code golf, so the shortest answer wins. Good luck!
  
[Answer]
# C 33
If just a function is allowed, then even c can compete.
*(For the record, 2 bytes saved thx to @Cool Guy. Mt thx comment is unexpectedly evaporated.)*
*1 more char saved thx @Mig*
```
f(a,c){printf("%s\n%*c",a,c,94);}
```
[Answer]
# Brainf\*ck - 133 bytes
```
+++++>>+>>+++>>+++++++++<<<<<<[[->++++++++++<]>>]<++++<<++<<<<--<,>[->+<<->]>>>,<<[->>-<<]<<[->>>>++++++++++<<<<]>>+[,.]>.>[->.<]>>>.
```
Expects input as `[0-9]{2}.*` e.g. "02Hello world!!!" would produce
```
Hello world!!!
 ^
```
[Answer]
# IA-32 machine code, 24 bytes
Hexdump:
```
66 b8 5e 00 42 38 22 75 fb 66 c7 02 0d 0a 42 42
c6 02 20 e2 fa 89 02 c3
```
It's a function (using MS `fastcall` convention) which updates the string in-place:
```
__declspec(naked) void __fastcall carrot(int n, char* s)
```
Assembly code:
```
    mov ax, '^'; // ah = 0, al = '^'
mystrlen:
    inc edx;
    cmp [edx], ah;
    jne mystrlen;
    mov word ptr [edx], '\r\n'; // append a newline
    inc edx;
mymemset:
    inc edx;
    mov byte ptr [edx], ' ';
    loop mymemset;
    mov [edx], eax; // append a caret and terminate the string
    ret;
```
It uses `WORD`-sized (16-bit) data in a few places. This has a penalty (1-byte prefix) in 32-bit code, but makes the code smaller anyway - using 32-bit data would put two zero bytes into code!
At the end, it writes 4 bytes (`eax`) instead of 2 bytes (`ax`) - the code is smaller that way, and 2 extra bytes of junk go after string termination, so no one notices them.
Usage:
```
int main()
{
    char s[100] = "Lorem ipsum, euro sit amet.";
    carrot(2, s); // credit to Digital Trauma for the name
    puts(s);
}
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth/commit/3313650c8fb6e8ba77f6479e269c5fd68526903a), 8
```
zp\^*tQd
```
This solution no longer works, since the commit after the one I've linked to as the language name changed `p` to have arity 1. There are several other ways of achieving a similar score in Pyth that still work today, like `zp+*dQ\^`.
If the string needs quotes, adding `v` to the beginning of the code works. If it has to be comma separated, it goes up to 10 bytes:
```
eQp\^*dthQ
```
[Answer]
# T-SQL, 90
While a fairly simple question, it's always interesting to try these in languages that really don't tend to support them well or golf well for that matter.
This answer is almost guaranteed to be the longest one.
This creates an inline table function for SQL Server that takes @n and @ as parameters and returns the results as a column. The carriage return is significant, otherwise I would need to use char(13).
```
CREATE FUNCTION G(@N INT,@ VARCHAR(MAX))RETURNS TABLE RETURN SELECT @+'
'+SPACE(@n-1)+'^'R
```
It's used in the following manner
```
SELECT R 
FROM (VALUES
    (1,'This is test 1'),
    (2,'This is test 2'),
    (3,'This is test 3'),
    (4,'This is test 4'),
    (5,'This is test 5')
    )T(n,S)
    CROSS APPLY G(n,S)
```
And returns
```
R
---------------
This is test 1
^
This is test 2
 ^
This is test 3
  ^
This is test 4
   ^
This is test 5
    ^
```
[Answer]
## Python, 27
```
lambda n,s:s+'\n%%%dc'%n%94
```
This uses two levels of string formatting.
And here's a **25 byte** solution partly stolen from feersum's answer (with the argument order reversed):
```
lambda*p:'%s\n%%%dc'%p%94
```
[Answer]
# Bash, 27
```
printf %s\\n%$[$1-1]s^ "$2"
```
### Output
```
$ ./carrot.sh 2 "Lorem ipsum, dollar sit amet."
Lorem ipsum, dollar sit amet.
 ^$ 
```
[Answer]
# sed, 16
```
2y/1/ /;2s/ $/^/
```
This is something of a testcase of [this meta answer](http://meta.codegolf.stackexchange.com/a/5344/11259). Specifically I am requiring that the number **N** is input in unary. E.g. for the caret in position 2, the input for **N** would be `11`. Also it is not strictly specified which order **S** and **N** should be, so here **S** goes first, followed by unary **N** on a new line, all through STDIN.
### Output:
```
$ { echo "Lorem ipsum, dollar sit amet."; echo 11; } | sed '2y/1/ /;2s/ $/^/'
Lorem ipsum, dollar sit amet.
 ^
$
```
[Answer]
# Python, 29
```
lambda n,s:s+'\n'+' '*~-n+'^'
```
Concatenates the string, a newline, `n-1` spaces, and a `^`.
[Answer]
# JavaScript (ES6): 63 62 56 52 32 bytes
Thanks to nderscore for greatly reducing the size of the code.
```
p=(a,b)=>b+`\n${' '.repeat(a)}^`
```
## Version that works across more browsers (47 bytes):
```
p=function(a,b){return b+`\n${' '.repeat(a)}^`}
```
[Answer]
# Python, 29
Here's a more fun way to do it in 29:
```
lambda*p:'%s\n%*s'%(p+('^',))
```
Example usage:
```
>>> f=lambda*p:'%s\n%*s'%(p+('^',))
>>> print f('lorem',5)
lorem
    ^
```
[Answer]
# CJam, 9 bytes
```
q~N@(S*'^
```
[Try it online.](http://cjam.aditsu.net/#code=q~N%40(S*'%5E&input=2%20%22Lorem%20ipsum%2C%20dollar%20sit%20amet.%22)
### How it works
```
q~  e# Read the input from STDIN and interpret it.
    e# This pushes the integer and the string on the stack.
N@  e# Push a linefeed an rotate the integer on top of it.
(S* e# Subtract 1 and push a string consisting of that many spaces.
'^  e# Push a caret.
```
[Answer]
# TI-BASIC, 10 (?) bytes
```
Disp Ans
Output(3,N,"^
```
Input is given in the variable N, as the question asks, but you can't use the letter var S as a string. In place of that, it takes string input from Ans, so to run the example in the OP: `2->N:"Lorem ipsum, dollar sit amet.":prgm<program name>`.
I'm aware that that probably doesn't count, though, as each colon-delimited segment is technically a separate statement; here's a **46-byte** program that takes input as `N "S"` (`2 "Lorem ipsum, dollar sit amet."`)
```
Input Str1
2+inString(Str1," 
//^there's a space after the quote
Disp sub(Str1,Ans,length(Str1)-Ans
Output(4,expr(sub(Str1,1,1)),"^
```
Both of these assume that the screen has been cleared before running.
[Answer]
# dc, 19
```
?pr256r^255/32*62+P
```
Input is from STDIN. `dc` strings are macro definitions and contained in `[` `]`. The string of spaces is generated by calculating the number that when expressed as a base 256 byte stream gives the string we need. The calculation is `((n ^ 256) / 255) * 32)`. This gives `n` spaces (ASCII character 32), but we need `n-1` followed by `^`, so we simply add 62 to the last base 256 digit.
### Output
```
$ dc -e '?pr256r^255/32*62+P' <<< "2 [Lorem ipsum, dollar sit amet.]"
Lorem ipsum, dollar sit amet.
 ^$
```
[Answer]
# C, ~~59~~ ~~57~~ 47 bytes
```
f(a,c){for(puts(a);--c;putchar(32));puts("^");}
```
Pretty straightforward. Ungolfed version:
```
f(char* a,int c){
    puts(a);        //Print the string first
    for(;--c;)      //Until number-1 is not 0
        putchar(32);//Print a space
    puts("^");      //Print a caret
}
```
Test it [here](http://rextester.com/ZHOEK53545)  
Thanks to [@anatolyg](https://codegolf.stackexchange.com/users/25315/anatolyg) for saving 10 bytes!
[Answer]
# C# 55
A function, concept similar to my C answer, but this time return is shorter than output.
```
string f(string a,int b){return a+'\n'+"^".PadLeft(b);}
```
[Answer]
# K, 21 bytes
```
{y,"\n",1_|"^",x#" "}
```
## Example:
```
ryan@DevPC-LX:~/golf/caret$ rlwrap k
K Console - Enter \ for help
  `0:{y,"\n",1_|"^",x#" "}[2;"Lorem ipsum, dollar sit amet."]
Lorem ipsum, dollar sit amet.
 ^  
```
## Explanation (`x` is the number, `y` is the string):
```
{                   }   enclosing function
               x#" "    repeat the space `x` times
           "^",         prepend the caret
          |             reverse the string to put the caret at the end
        1_              drop the extra space
   "\n",                prepend a newline
 y,                     prepend the text
```
[Answer]
## SAS, 35 bytes
```
%macro a(n,s);put &s/@&n."^";%mend;
```
That is the SAS equivalent of a naked function; to add the data step to call it (equivalent to C main function to call it) would be a bit more (9 more bytes - Ty Alex), but I think that's not necessary for this purpose. How it would be called:
```
data;
%a(3,"My String");
run;
```
There is a macro-only implementation but it's much longer, even if you allow it to give a warning about invalid parameters on n=1.
If we could use pre-defined parameters, SAS would be quite short comparatively on this one, which is a rarity for a language most definitely not intended to be short.
---
If a dataset is allowed to be the source of input, which is how you would 'do it' in SAS (or by %let statements), but is probably not permitted, this is even shorter (**27 bytes**, which actually could be 25 if you guaranteed the dataset was constructed immediately prior to running this [as you could then just use `set;`]):
(pre-existing dataset)
```
data b;
  n=3;
  s="My String";
run;
```
(actual code)
```
data;set b;put s/@n"^";run;
```
[Answer]
# Matlab/Octave, 41
```
@(n,s)sprintf('%s\n%s^',s,ones(1,n-1)+31)
```
This is an anonymous function that returns the string. This produces a warning, which can be suppressed by previously calling `warning off`.
[Answer]
# R, ~~49~~ ~~48~~ 46
As an unnamed function that outputs to STDOUT. Thanks to @Flounderer for the improvement.
uses strwrap now to ident the caret to n-1. cat uses a seperator of \n rather than empty string.
```
function(n,s)cat(s,strwrap('^',,n-1),sep='\n')
```
Test run
```
> f=function(n,s)cat(s,strwrap('^',,n-1),sep='\n')
> f(29,'The caret should point here v hopefully')
The caret should point here v hopefully
                            ^
>
```
[Answer]
# Python3, ~~38~~ 36 bytes
```
def f(s,i):return s+'\n'+' '*~-i+'^'
# OR 
def f(s,i):print(s+'\n'+' '*~-i+'^')
```
Test it [here](http://rextester.com/XVS32879)  
Thanks to [@Dennis](https://codegolf.stackexchange.com/users/12012/dennis) for saving 2 bytes!
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), ~~32~~ 31 bytes
```
: b type cr 1- spaces 94 emit ;
```
[Try it online!](https://tio.run/##FckxDoAgDAXQq/wwi4mJDuoVvARoURIIpMXB01ed3vBC4XbZM/yoLvBoTyXsjMFCqttJMI@gHBtWnSAGW2HKiFXu3OEoKTmGfO0ytd7A6ws "Forth (gforth) – Try It Online")
Input is given as `<number> s" <string>" b`.
Note the required space after `s"`.
-1 byte from Bubbler.
Shorter than MAWP lol
[Answer]
# Julia, 27 bytes
```
(n,s)->s*"\n"*" "^(n-1)*"^"
```
This creates an unnamed function that accepts an integer and string as input and returns a string. To call it, give it a name, e.g. `f=(n,s)->...`.
All that's happening here is we're appending a newline, `n-1` spaces, and the caret. String concatenation is performed using `*` and string repetition with `^`.
Ungolfed:
```
function f(n, s)
    s * "\n" * " "^(n-1) * "^"
end
```
Example:
```
julia> println(f(2, "Lorem ipsum, dollar sit amet."))
Lorem ipsum, dollar sit amet.
 ^
```
[Answer]
# PHP (CLI) - 42
```
<?=sprintf("%s\n%$argv[1]s",$argv[2],'^');
```
Call it from the command line:
```
php pointer.php 2 "Lorem ipsum, dollar sit amet."
```
[Answer]
# Matlab, 25
This one is extremely cheeky. Apparently displays prints non-printable characters as spaces. The following code defines a function named `ans`, that meets the specs.
```
@(N,S)[S 10 ones(N-1) 94]
```
so calling this function like this:
```
ans(2, 'Lorem ipsum, dollar sit amet.')
```
gives the output:
```
ans =
Lorem ipsum, dollar sit amet.
 ^
```
I always dislike the `ans =` part in Matlab answers. If this is a problem, I need to add 6 bytes... but I have always seen it like this in Matlab answers.
Note that running this code overwrites the variable `ans`, so you need to redefine the function if you want to use it a second time!
[Answer]
My first shot at codegolf
# Java, 133 65
```
String g(int i,String s){for(s+="\n";--i>0;)s+=" ";return s+"^";}
```
I'm sure it can be reduced even more.
Old code
```
public void go(int i,String s){System.out.println(s);IntStream.range(1,i).forEach(j->System.out.print(" "));System.out.println("^");}
```
[Answer]
# Pascal: 57 characters
```
procedure p(n:Byte;s:string);begin
Write(s,#10,'^':n)end;
```
Just to demonstrate Pascal's cute little output formatting. The rest is depressing.
[Answer]
# Swift, 41
It is disappointing that Swift does not have operator `*` on `Array` or `String`.
```
{$1+reduce(0..<$0,"\n",{$0.0+" "})+"^"}
```
[Answer]
# [MAWP v1.02](https://esolangs.org/wiki/MAWP), 37 53 bytes
```
%|0~[;]25W3M;@~(%)~_1A[1A~25WWM~]~1A[1A84W;]85W7M2W;.
```
Takes input as `[S][a]`, with no spaces between S and n.
Since the online interpreter takes only one line of input, the string and number are printed together.
[Try it!](https://8dion8.github.io/?code=%25%7C0%7E%5B%3B%5D25W3M%3B%40%7E(%25)%7E_1A%5B1A%7E25WWM%7E%5D%7E1A%5B1A84W%3B%5D85W7M2W%3B.&input=Hows%20it%20going13)
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 16 bytes
```
$_.=$"x<>;s; $;^
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXs9WRanCxs662FpBxTru//@QjMxiBSBKVChJLS7hMvmXX1CSmZ9X/F/X11TPwNDgv24BAA "Perl 5 – Try It Online")
---
# [Perl 5](https://www.perl.org/) `-p`, 16 bytes
```
$\=$"x(<>-1)."^"
```
[Try it online!](https://tio.run/##K0gtyjH9/18lxlZFqULDxk7XUFNPKU7p//@QjMxiBSBKVChJLS7hMv6XX1CSmZ9X/F/X11TPwNDgv24BAA "Perl 5 – Try It Online")
]