Coefficients and wavefunction in quantum mechanics In general quantum mechanics we represent the state of a system with a state vector $| \psi \rangle $ in some Hilbert space in some base. Assuming a complete discrete set of bases vectors $ |n \rangle $ we can write the state $\psi $ as: 
$$| \psi \rangle = \sum_n ^N c_n |n \rangle   $$
Having by definition an inner product we can see that  $c_n = \langle \psi | n \rangle  $. This is the projection of the state vector on the base vector $n$. This coefficient squared, we say, gives us the probability of finding out system in the state $n$. 
As I understand so far $ c_n $ is a complex number. Also, as a function, $\psi$ is a function of variable same as the variable of $n$, where $n$ are also functions.
In position representation we have a base denoted as $| x \rangle $. So to the question.
I would say that:
$$| \psi \rangle = \sum_n ^N c_n |x \rangle   $$
$$c_n = \langle x| \psi \rangle $$ where $|x \rangle =f(x) $ so that, in this bases $| \psi \rangle = \psi (x)$, x meaning position.
My problem is that from what I read, what holds is this:
$$c_n = c_n (x) = \langle x | \psi \rangle = \psi (x) ,$$ $ \psi (x)$ being the wavefunction- the projection of $|\psi \rangle $ on $|x \rangle $ and
$$\psi(x) = \sum_n ^N c' _n u_n (x)  $$, where $ u_n (x)$ constitute a  base for the position representation. So, the probability of finding the particle in position $x$ is $| \psi (x) |^2 $. But I thought that $|x \rangle $ was already our base in space. 
Are $u(x) $ and $| x \rangle $ the same or not? If not, why do we need $u(x)$?
Is $\psi (x) $ as given in the end by the inner product a function that can be expressed in functions of $x$ that constitute a base or is it a number as a result of an inner product giving the coefficient in a sum? Can the coefficients be functions and if yes, when? Is it correct to say that the wavefunction in secondary to the state vector and if so, how is it a function if it is a coefficient?
There is certainly something here I don't get and I would really like your help and clarifications.
Note: I wrote the question with sums and not integrals for convenience. An answer might have as well integrals, there is clearly no problem. Also I' ve had a look in these questions and answers: 
General wavefunction and Schrödinger Equation
State of a system in Quantum Mechanics and state vectors
Representations in quantum mechanics
Vector representation of wavefunction in quantum mechanics?
but I'm not sure they address my problem.
 A: Your confusion stems from the fact that $\lvert x \rangle$ is not inside the Hilbert space of states. It cannot be because $\langle x \vert x \rangle = \delta(x-x) = \delta(0)$ is not an allowed value for an inner product in a Hilbert space to have. There are several things to say about $\lvert x \rangle$:


*

*If you want to make precise what kind of objects $\langle x \rvert$ and $\lvert x \rangle$ are, you need the notion of rigged Hilbert spaces. A nice answer about them is here by user1504.

*In general, the "eigenstates" associated to eigenvalues in the continuous spectrum of an unbounded operator do not lie inside the space of states. Only the discrete eigenvalues have proper eigenvectors.

*The set of objects $\lvert x \rangle$ is uncountable and hence not a basis in the usual sense. In particular, writing $\sum_x c_x \lvert x \rangle$ doesn't make sense because series over uncountable sets do not converrge. The analogon for $\lvert \psi =\sum_n c_n\lvert n \rangle$ for a countable Hilbert basis $\lvert n \rangle$ is writing
$$ \lvert\psi\rangle = \int \psi(x)\lvert x \rangle \mathrm{d}x\tag{1}$$
where writing $\psi(x) = \langle x \vert \psi \rangle$ leads to
$$ 1 = \int \lvert x \rangle \langle x \rvert \mathrm{d}x$$
It is in the sense of $(1)$ that the wavefunction gives the coefficients in the position basis.
A: Assuming everything is defined in the correct Hilbert spaces, project the decomposition
$$
|\psi\rangle = \sum_n {c_n |n\rangle}
$$
onto the position kets ("states") $|x\rangle$ and obtain
$$
\psi(x) = \langle x |\psi\rangle = \sum_n {c_n \langle x |n\rangle} = \sum_n {c_n u_n(x)}
$$
where the $u_n(x) = \langle x |n\rangle$ are the wavefunctions corresponding to the $|n\rangle$ states. So the result is a decomposition of a wave function into basis wave functions with coefficients corresponding to the decomposition of the state into basis states. What happened is that we subtly changed the representation space.
